pub struct SimpleResponseBuilder { /* private fields */ }
Expand description
§SIP Response Builder
The SimpleResponseBuilder provides a streamlined approach to creating SIP response messages as defined in RFC 3261.
§SIP Response Overview
SIP (Session Initiation Protocol) responses are messages sent by servers to clients in response to client requests. Each response contains a status code indicating the outcome, a reason phrase, and various headers providing additional information.
A typical SIP response looks like:
SIP/2.0 200 OK
Via: SIP/2.0/UDP server10.example.com;branch=z9hG4bK4b43c2ff8.1;received=192.0.2.3
Via: SIP/2.0/UDP client.example.com:5060;branch=z9hG4bK74bf9;received=192.0.2.201
From: Alice <sip:alice@example.com>;tag=9fxced76sl
To: Bob <sip:bob@example.com>;tag=8321234356
Call-ID: 3848276298220188511@client.example.com
CSeq: 1 INVITE
Contact: <sip:bob@client.example.com>
Content-Type: application/sdp
Content-Length: 147
[SDP message body]
§SIP Response Status Codes
SIP defines several categories of status codes:
- 1xx (Provisional): Request received and being processed (e.g., 100 Trying, 180 Ringing)
- 2xx (Success): Request was successfully received, understood, and accepted (e.g., 200 OK)
- 3xx (Redirection): Further action needs to be taken to complete the request (e.g., 302 Moved Temporarily)
- 4xx (Client Error): Request contains bad syntax or cannot be fulfilled at this server (e.g., 404 Not Found)
- 5xx (Server Error): Server failed to fulfill an apparently valid request (e.g., 500 Server Internal Error)
- 6xx (Global Failure): Request cannot be fulfilled at any server (e.g., 603 Decline)
§Key SIP Response Headers
- Via: Indicates the path taken by the request (copied from request with additional parameters)
- From: Identifies the logical initiator of the request (copied from request)
- To: Identifies the logical recipient of the request (copied from request, tag added if needed)
- Call-ID: Unique identifier for this call or registration (copied from request)
- CSeq: Sequence number and method for ordering requests (copied from request)
- Contact: Direct URI at which the responder can be reached (for dialog-establishing responses)
- Content-Type/Content-Length: Describes the message body, if present
§Dialog Creation and Maintenance
Certain responses help establish and maintain dialogs between SIP user agents:
- 2xx responses to INVITE: Establish dialogs and must include Contact headers
- 101-199 responses with to-tag: Establish early dialogs when responding to INVITE
- Responses within dialogs: Must maintain dialog state with proper tags and CSeq values
§Transaction Model
SIP responses work within transactions to provide reliability:
- INVITE transaction responses: May include provisional (1xx) responses, followed by final responses
- Non-INVITE transaction responses: Typically have single final response
- 2xx responses to INVITE: Establish separate transactions for reliability through ACK
§Benefits of Using SimpleResponseBuilder
The SimpleResponseBuilder provides several advantages:
- Ergonomic API: Fluent interface with method chaining
- Default Handling: Sets reasonable defaults for many fields
- RFC Compliance: Ensures compliance with SIP standards and conventions
- Header Management: Properly formats and validates SIP headers
- Status-Specific Builders: Convenience constructors for common responses
- Type Safety: Leverages Rust’s type system to prevent invalid messages
The examples below demonstrate how to create various types of SIP responses for common scenarios. The SimpleResponseBuilder provides a streamlined approach to creating SIP response messages.
§Examples
§Creating a Basic SIP Response
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Method, StatusCode};
let response = SimpleResponseBuilder::new(StatusCode::Ok, Some("OK"))
.from("Alice", "sip:alice@example.com", Some("1928301774"))
.to("Bob", "sip:bob@example.com", Some("a6c85cf"))
.call_id("a84b4c76e66710@pc33.atlanta.com")
.cseq(1, Method::Invite)
.via("pc33.atlanta.com", "UDP", Some("z9hG4bK776asdhds"))
.build();
assert_eq!(response.status_code(), 200);
§Using Convenience Constructors
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::Method;
// 200 OK response
let ok = SimpleResponseBuilder::ok()
.from("Alice", "sip:alice@example.com", Some("1928301774"))
.to("Bob", "sip:bob@example.com", Some("a6c85cf"))
.call_id("a84b4c76e66710@pc33.atlanta.com")
.cseq(1, Method::Invite)
.build();
// 100 Trying response
let trying = SimpleResponseBuilder::trying()
.from("Alice", "sip:alice@example.com", Some("1928301774"))
.to("Bob", "sip:bob@example.com", None)
.call_id("a84b4c76e66710@pc33.atlanta.com")
.cseq(1, Method::Invite)
.build();
// 180 Ringing response
let ringing = SimpleResponseBuilder::ringing()
.from("Alice", "sip:alice@example.com", Some("1928301774"))
.to("Bob", "sip:bob@example.com", Some("a6c85cf"))
.call_id("a84b4c76e66710@pc33.atlanta.com")
.cseq(1, Method::Invite)
.build();
§Adding SDP Content
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Method, StatusCode};
use rvoip_sip_core::sdp::SdpBuilder;
use rvoip_sip_core::sdp::attributes::MediaDirection;
// Create an SDP body using the SdpBuilder pattern
let sdp_body = SdpBuilder::new("Session")
.origin("bob", "2890844527", "2890844527", "IN", "IP4", "127.0.0.1")
.connection("IN", "IP4", "127.0.0.1")
.time("0", "0")
.media_audio(49172, "RTP/AVP")
.formats(&["0"])
.rtpmap("0", "PCMU/8000")
.done()
.build()
.expect("Valid SDP");
let response = SimpleResponseBuilder::ok()
.from("Bob", "sip:bob@example.com", Some("a6c85cf"))
.to("Alice", "sip:alice@example.com", Some("1928301774"))
.call_id("a84b4c76e66710@pc33.atlanta.com")
.cseq(1, Method::Invite)
.content_type("application/sdp")
.body(sdp_body.to_string())
.build();
§Working with Contact Headers
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Method, StatusCode};
let response = SimpleResponseBuilder::ok()
.from("Bob", "sip:bob@example.com", Some("a6c85cf"))
.to("Alice", "sip:alice@example.com", Some("1928301774"))
.call_id("a84b4c76e66710@pc33.atlanta.com")
.cseq(1, Method::Invite)
.contact("sip:bob@192.168.1.2:5060", Some("Bob"))
.build();
§Creating Responses from Existing Ones
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Response, StatusCode};
// Create or get a response from somewhere
let response = Response::new(StatusCode::Ok);
// Create a builder from the existing response
let modified_response = SimpleResponseBuilder::from_response(response)
.from("Bob", "sip:bob@example.com", Some("a6c85cf"))
.to("Alice", "sip:alice@example.com", Some("1928301774"))
.build();
Implementations§
Source§impl SimpleResponseBuilder
impl SimpleResponseBuilder
Sourcepub fn new(status: StatusCode, reason: Option<&str>) -> Self
pub fn new(status: StatusCode, reason: Option<&str>) -> Self
Create a new SimpleResponseBuilder with the specified status code and optional reason phrase
This is the main entry point for creating a SIP response builder. Status codes are defined in RFC 3261 Section 21.
§Parameters
status
: The SIP status code (e.g., StatusCode::Ok (200), StatusCode::NotFound (404))reason
: Optional custom reason phrase (if None, the default for the status code will be used)
§Returns
A new SimpleResponseBuilder
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::StatusCode;
// Create with default reason phrase
let ok_builder = SimpleResponseBuilder::new(StatusCode::Ok, None);
// Create with custom reason phrase
let not_found_builder = SimpleResponseBuilder::new(StatusCode::NotFound, Some("User Not Available"));
Sourcepub fn response_from_request(
request: &Request,
status: StatusCode,
reason: Option<&str>,
) -> Self
pub fn response_from_request( request: &Request, status: StatusCode, reason: Option<&str>, ) -> Self
Create a response for a request with automatic header copying according to SIP standards
This method creates a response based on an existing request, automatically copying the headers that should be included in responses according to SIP standards.
§Parameters
request
: The SIP request for which to create a responsestatus
: The status code for the responsereason
: Optional custom reason phrase (if None, the default will be used)
§Returns
A SimpleResponseBuilder with appropriate headers copied from the request
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{StatusCode, Request, Method, Version};
use rvoip_sip_core::Uri;
use std::str::FromStr;
// In a real example, you'd receive an actual request from a client
// Here we just create a minimal request for demonstration
let uri = Uri::from_str("sip:bob@example.com").unwrap();
let request = Request::new(Method::Invite, uri);
// Create a 200 OK response with all appropriate headers copied
let ok_response = SimpleResponseBuilder::response_from_request(&request, StatusCode::Ok, None)
.contact("sip:bob@192.168.1.2:5060", None)
.build();
Sourcepub fn dialog_response(
request: &Request,
status: StatusCode,
reason: Option<&str>,
) -> Self
pub fn dialog_response( request: &Request, status: StatusCode, reason: Option<&str>, ) -> Self
Create a standard dialog-establishing response
This is a convenience method that creates a response with the standard set of headers needed for dialog establishment, including adding a local tag to the To header if not present.
§Parameters
request
: The SIP request for which to create a responsestatus
: The status code for the responsereason
: Optional custom reason phrase (if None, the default will be used)
§Returns
A SimpleResponseBuilder with standard dialog headers
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{StatusCode, Request, Method, Version};
use rvoip_sip_core::Uri;
use std::str::FromStr;
use rvoip_sip_core::types::from::From as FromType;
use rvoip_sip_core::types::to::To as ToType;
use rvoip_sip_core::types::call_id::CallId;
// In a real example, you'd receive an actual request from a client
// Here we just create a minimal request for demonstration
let uri = Uri::from_str("sip:bob@example.com").unwrap();
let request = Request::new(Method::Invite, uri);
// Create a 200 OK response for dialog establishment
let ok_response = SimpleResponseBuilder::dialog_response(&request, StatusCode::Ok, None)
.contact("sip:bob@192.168.1.2:5060", None)
.build();
Sourcepub fn error_response(
request: &Request,
status: StatusCode,
reason: Option<&str>,
) -> Self
pub fn error_response( request: &Request, status: StatusCode, reason: Option<&str>, ) -> Self
Create a minimal error response
This is a convenience method that creates a response with the minimal set of headers needed for error responses.
§Parameters
request
: The SIP request for which to create a responsestatus
: The status code for the responsereason
: Optional custom reason phrase (if None, the default will be used)
§Returns
A SimpleResponseBuilder with minimal headers for error responses
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{StatusCode, Request, Method, Version};
use rvoip_sip_core::Uri;
use std::str::FromStr;
use rvoip_sip_core::types::from::From as FromType;
use rvoip_sip_core::types::to::To as ToType;
use rvoip_sip_core::types::call_id::CallId;
// In a real example, you'd receive an actual request from a client
// Here we just create a minimal request for demonstration
let uri = Uri::from_str("sip:bob@example.com").unwrap();
let request = Request::new(Method::Invite, uri);
// Create a 404 Not Found error response
let not_found = SimpleResponseBuilder::error_response(&request, StatusCode::NotFound, None)
.build();
Sourcepub fn from_response(response: Response) -> Self
pub fn from_response(response: Response) -> Self
Create from an existing Response object
This allows you to modify an existing response by using the builder pattern.
§Parameters
response
: An existing SIP Response object
§Returns
A SimpleResponseBuilder initialized with the provided response
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Response, StatusCode};
// Create a response or get it from somewhere
let response = Response::new(StatusCode::Ok);
// Create a builder from the existing response
let builder = SimpleResponseBuilder::from_response(response);
Sourcepub fn ok() -> Self
pub fn ok() -> Self
Create a 200 OK response
This is a convenience constructor for creating a 200 OK response as specified in RFC 3261 Section 21.2.1. 200 OK responses indicate the request was successful.
§Returns
A SimpleResponseBuilder with a 200 OK status
§Examples
§Basic 200 OK Response
use rvoip_sip_core::builder::SimpleResponseBuilder;
let builder = SimpleResponseBuilder::ok();
§Complete 200 OK Response to an INVITE
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::Method;
// Create a 200 OK response accepting an INVITE request
let ok_response = SimpleResponseBuilder::ok()
// Copy headers from the original request
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", Some("b5qt9xl3")) // Add local tag
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite) // Same CSeq and method as request
// Copy Via headers from request (in same order)
.via("proxy.example.com:5060", "UDP", Some("z9hG4bK776asdhds"))
.via("alice-pc.example.com:5060", "UDP", Some("z9hG4bK123abcde"))
// Contact header is required in 2xx responses to INVITE
.contact("sip:bob@192.168.1.2:5060", Some("Bob"))
.build();
§200 OK Response with SDP Answer
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::Method;
use rvoip_sip_core::sdp::SdpBuilder;
use rvoip_sip_core::sdp::attributes::MediaDirection;
// Create an SDP answer using the SdpBuilder pattern
let sdp_answer = SdpBuilder::new("SIP Call")
.origin("bob", "2890844527", "2890844527", "IN", "IP4", "192.168.1.2")
.connection("IN", "IP4", "192.168.1.2")
.time("0", "0")
.media_audio(49172, "RTP/AVP")
.formats(&["0", "8"])
.rtpmap("0", "PCMU/8000")
.rtpmap("8", "PCMA/8000")
.direction(MediaDirection::SendRecv)
.done()
.build()
.expect("Valid SDP");
// Create a 200 OK response with SDP answer to INVITE
let ok_with_sdp = SimpleResponseBuilder::ok()
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", Some("b5qt9xl3"))
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
.via("proxy.example.com:5060", "UDP", Some("z9hG4bK776asdhds"))
.contact("sip:bob@192.168.1.2:5060", None)
// Add SDP body with selected codecs
.content_type("application/sdp")
.body(sdp_answer.to_string())
.build();
Sourcepub fn trying() -> Self
pub fn trying() -> Self
Create a 100 Trying response
This is a convenience constructor for creating a 100 Trying response as specified in RFC 3261 Section 21.1.1. 100 Trying responses indicate the request has been received and the server is working on it.
§Returns
A SimpleResponseBuilder with a 100 Trying status
§Examples
§Basic 100 Trying Response
use rvoip_sip_core::builder::SimpleResponseBuilder;
let builder = SimpleResponseBuilder::trying();
§Complete 100 Trying Response to an INVITE
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::Method;
// Create a 100 Trying response to acknowledge receipt of an INVITE
// This is typically sent by a proxy or UAS while processing the request
let trying_response = SimpleResponseBuilder::trying()
// Copy headers from the original request (no tags added for provisional responses)
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", None) // No To tag in initial provisional response
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
// Copy all Via headers from request (in same order)
.via("proxy.example.com:5060", "UDP", Some("z9hG4bK776asdhds"))
.via("alice-pc.example.com:5060", "UDP", Some("z9hG4bK123abcde"))
.build();
§100 Trying with Server Information
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Method, TypedHeader};
// Create a 100 Trying response with Server header
let trying_with_server = SimpleResponseBuilder::trying()
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", None)
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
.via("proxy.example.com:5060", "UDP", Some("z9hG4bK776asdhds"))
// Add Server header to identify the server software
.header(TypedHeader::Server(vec![
"RVoIP-Proxy/1.0".to_string(),
"(Linux)".to_string()
]))
.build();
Sourcepub fn ringing() -> Self
pub fn ringing() -> Self
Create a 180 Ringing response
This is a convenience constructor for creating a 180 Ringing response as specified in RFC 3261 Section 21.1.2. 180 Ringing responses indicate the user agent has located the callee and is alerting them.
§Returns
A SimpleResponseBuilder with a 180 Ringing status
§Examples
§Basic 180 Ringing Response
use rvoip_sip_core::builder::SimpleResponseBuilder;
let builder = SimpleResponseBuilder::ringing();
§Complete 180 Ringing Response for an INVITE
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::Method;
// Create a 180 Ringing response to indicate the destination is being alerted
let ringing_response = SimpleResponseBuilder::ringing()
// Copy headers from the original request
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", Some("b5qt9xl3")) // Add To tag to establish early dialog
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
// Copy Via headers from request (in same order)
.via("proxy.example.com:5060", "UDP", Some("z9hG4bK776asdhds"))
.via("alice-pc.example.com:5060", "UDP", Some("z9hG4bK123abcde"))
// Contact header in provisional responses helps with early media
.contact("sip:bob@192.168.1.2:5060", None)
.build();
§180 Ringing with Early Media (SDP)
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::Method;
use rvoip_sip_core::sdp::SdpBuilder;
use rvoip_sip_core::sdp::attributes::MediaDirection;
// Create an SDP for early media (ringback tone) using SdpBuilder pattern
let early_media_sdp = SdpBuilder::new("Ringback Tone")
.origin("bob", "2890844527", "2890844527", "IN", "IP4", "192.168.1.2")
.connection("IN", "IP4", "192.168.1.2")
.time("0", "0")
.media_audio(49172, "RTP/AVP")
.formats(&["0"])
.rtpmap("0", "PCMU/8000")
.direction(MediaDirection::SendOnly) // SendOnly for ringback tone
.done()
.build()
.expect("Valid SDP");
// Create a 180 Ringing response with early media (ringback tone)
let ringing_with_media = SimpleResponseBuilder::ringing()
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", Some("b5qt9xl3"))
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
.via("proxy.example.com:5060", "UDP", Some("z9hG4bK776asdhds"))
.contact("sip:bob@192.168.1.2:5060", None)
// Add SDP body for early media (ringback tone)
.content_type("application/sdp")
.body(early_media_sdp.to_string())
.build();
Sourcepub fn bad_request() -> Self
pub fn bad_request() -> Self
Create a 400 Bad Request response
This is a convenience constructor for creating a 400 Bad Request response as specified in RFC 3261 Section 21.4.1. 400 Bad Request responses indicate the server couldn’t understand the request due to malformed syntax.
§Returns
A SimpleResponseBuilder with a 400 Bad Request status
§Examples
§Basic 400 Bad Request Response
use rvoip_sip_core::builder::SimpleResponseBuilder;
let builder = SimpleResponseBuilder::bad_request();
§Complete 400 Bad Request Response with Reason
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Method, TypedHeader, Warning};
use rvoip_sip_core::types::uri::Uri;
use std::str::FromStr;
// Create warning with proper Uri (not string)
let agent_uri = Uri::from_str("sip:proxy.example.com").unwrap();
let warning = Warning::new(399, agent_uri, "Malformed Contact header");
// Create a 400 Bad Request response for a malformed request
let bad_request_response = SimpleResponseBuilder::bad_request()
// Include original headers when possible
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", None) // No To tag for error responses
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
// Copy topmost Via header only for error responses
.via("alice-pc.example.com:5060", "UDP", Some("z9hG4bK123abcde"))
// Add a Warning header with more information about the error
.header(TypedHeader::Warning(vec![warning]))
.build();
§400 Bad Request with Detailed Error Message
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Method, TypedHeader, Warning};
// Create an explanation of the syntax error in plain text
let error_body =
"The request contained a malformed header:\r\n\
Contact: <sip:bob@example.com missing-bracket\r\n\
\r\n\
The correct format should be:\r\n\
Contact: <sip:bob@example.com>";
// Create a 400 Bad Request with a text explanation
let detailed_response = SimpleResponseBuilder::bad_request()
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", None)
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
.via("alice-pc.example.com:5060", "UDP", Some("z9hG4bK123abcde"))
// Add a detailed explanation in the body
.content_type("text/plain")
.body(error_body)
.build();
Sourcepub fn not_found() -> Self
pub fn not_found() -> Self
Create a 404 Not Found response
This is a convenience constructor for creating a 404 Not Found response as specified in RFC 3261 Section 21.4.4. 404 Not Found responses indicate the server has definitive information that the user does not exist at the domain specified in the Request-URI.
§Returns
A SimpleResponseBuilder with a 404 Not Found status
§Examples
§Basic 404 Not Found Response
use rvoip_sip_core::builder::SimpleResponseBuilder;
let builder = SimpleResponseBuilder::not_found();
§Complete 404 Not Found Response
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::Method;
// Create a 404 Not Found response to an INVITE
let not_found_response = SimpleResponseBuilder::not_found()
// Include original headers from the request
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Unknown", "sip:unknown@example.com", None) // No To tag for error responses
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
// Only include the top Via header in error responses
.via("alice-pc.example.com:5060", "UDP", Some("z9hG4bK123abcde"))
.build();
§404 Not Found with Alternative Destination
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Method, TypedHeader};
// Create a 404 Not Found with alternative contact information
let alternative_response = SimpleResponseBuilder::not_found()
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@old-domain.example.com", None)
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
.via("alice-pc.example.com:5060", "UDP", Some("z9hG4bK123abcde"))
// Add a Contact header with alternative location
.contact("sip:bob@new-domain.example.com", Some("Bob"))
// Note: Reason header commented out until implemented
/*
// Add a Reason header explaining the change
.header(TypedHeader::Reason(
Reason::new("SIP", 301, Some("User moved permanently"))
))
*/
.build();
Sourcepub fn server_error() -> Self
pub fn server_error() -> Self
Create a 500 Server Error response
This is a convenience constructor for creating a 500 Server Internal Error response as specified in RFC 3261 Section 21.5.1. 500 Server Internal Error responses indicate the server encountered an unexpected condition that prevented it from fulfilling the request.
§Returns
A SimpleResponseBuilder with a 500 Server Internal Error status
§Examples
§Basic 500 Server Error Response
use rvoip_sip_core::builder::SimpleResponseBuilder;
let builder = SimpleResponseBuilder::server_error();
§Complete 500 Server Error Response
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::Method;
// Create a 500 Server Error response for an INVITE
let server_error_response = SimpleResponseBuilder::server_error()
// Include original headers from the request
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", None) // No To tag for error responses
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
// Only include the top Via header in error responses
.via("alice-pc.example.com:5060", "UDP", Some("z9hG4bK123abcde"))
// Note: RetryAfter header commented out until implemented
/*
// Include a Retry-After header suggesting when to retry
.header(TypedHeader::RetryAfter(RetryAfter::new(300))) // Retry after 5 minutes
*/
.build();
§500 Server Error with Detailed Warning
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{Method, TypedHeader, Warning};
use rvoip_sip_core::types::uri::Uri;
use std::str::FromStr;
// Create warning URIs
let agent_uri = Uri::from_str("sip:sip.example.com").unwrap();
// Create a 500 Server Error with detailed warning information
let detailed_error = SimpleResponseBuilder::server_error()
.from("Alice", "sip:alice@example.com", Some("a73kszlfl"))
.to("Bob", "sip:bob@example.com", None)
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.168.1.2")
.cseq(1, Method::Invite)
.via("alice-pc.example.com:5060", "UDP", Some("z9hG4bK123abcde"))
// Add informative headers
.header(TypedHeader::Warning(vec![
Warning::new(399, agent_uri.clone(), "Database connection timeout"),
Warning::new(399, agent_uri, "Server is under heavy load")
]))
// Note: RetryAfter and Server headers commented out until implemented
/*
.header(TypedHeader::RetryAfter(RetryAfter::new(120))) // Retry after 2 minutes
.header(TypedHeader::Server(vec![
"SIP-Core/1.0".to_string(),
"(Maintenance Mode)".to_string()
]))
*/
.build();
Sourcepub fn from(self, display_name: &str, uri: &str, tag: Option<&str>) -> Self
pub fn from(self, display_name: &str, uri: &str, tag: Option<&str>) -> Self
Add a From header with optional tag parameter
Creates and adds a From header as specified in RFC 3261 Section 20.20. In responses, the From header is copied from the request.
§Parameters
display_name
: The display name for the From header (e.g., “Alice”)uri
: The URI for the From header (e.g., “sip:alice@example.com”)tag
: Optional tag parameter (should be the same as in the request)
§Returns
Self for method chaining
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::StatusCode;
let builder = SimpleResponseBuilder::new(StatusCode::Ok, None)
.from("Alice", "sip:alice@example.com", Some("1928301774"));
Sourcepub fn to(self, display_name: &str, uri: &str, tag: Option<&str>) -> Self
pub fn to(self, display_name: &str, uri: &str, tag: Option<&str>) -> Self
Add a To header with optional tag parameter
Creates and adds a To header as specified in RFC 3261 Section 20.39. In responses, the To header is copied from the request and a tag is added if it didn’t already have one.
§Parameters
display_name
: The display name for the To header (e.g., “Bob”)uri
: The URI for the To header (e.g., “sip:bob@example.com”)tag
: Optional tag parameter (should be added by UAS for dialogs)
§Returns
Self for method chaining
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::StatusCode;
let builder = SimpleResponseBuilder::new(StatusCode::Ok, None)
.to("Bob", "sip:bob@example.com", Some("a6c85cf"));
Sourcepub fn call_id(self, call_id: &str) -> Self
pub fn call_id(self, call_id: &str) -> Self
Add a Call-ID header
Creates and adds a Call-ID header as specified in RFC 3261 Section 20.8. In responses, the Call-ID is copied from the request.
§Parameters
call_id
: The Call-ID value (e.g., “f81d4fae-7dec-11d0-a765-00a0c91e6bf6@example.com”)
§Returns
Self for method chaining
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::StatusCode;
let builder = SimpleResponseBuilder::new(StatusCode::Ok, None)
.call_id("f81d4fae-7dec-11d0-a765-00a0c91e6bf6@host.example.com");
Sourcepub fn cseq(self, seq: u32, method: Method) -> Self
pub fn cseq(self, seq: u32, method: Method) -> Self
Add a CSeq header for responses (requires method)
Creates and adds a CSeq header as specified in RFC 3261 Section 20.16. In responses, the CSeq is copied from the request, including both the sequence number and method.
§Parameters
seq
: The sequence number (e.g., 1, 2, 3)method
: The method in the CSeq header (e.g., Method::Invite)
§Returns
Self for method chaining
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{StatusCode, Method};
let builder = SimpleResponseBuilder::new(StatusCode::Ok, None)
.cseq(1, Method::Invite);
Sourcepub fn via(self, host: &str, transport: &str, branch: Option<&str>) -> Self
pub fn via(self, host: &str, transport: &str, branch: Option<&str>) -> Self
Add a Via header with optional branch parameter
Creates and adds a Via header as specified in RFC 3261 Section 20.42. In responses, the Via headers are copied from the request in the same order.
§Parameters
host
: The host or IP address (e.g., “192.168.1.1” or “example.com:5060”)transport
: The transport protocol (UDP, TCP, TLS, etc.)branch
: Optional branch parameter (should be the same as in the request)
§Returns
Self for method chaining
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::StatusCode;
let builder = SimpleResponseBuilder::new(StatusCode::Ok, None)
.via("192.168.1.1:5060", "UDP", Some("z9hG4bK776asdhds"));
Sourcepub fn contact(self, uri: &str, display_name: Option<&str>) -> Self
pub fn contact(self, uri: &str, display_name: Option<&str>) -> Self
Add a Contact header
Creates and adds a Contact header as specified in RFC 3261 Section 20.10. In responses, the Contact header provides a URI for subsequent requests in the dialog.
§Parameters
uri
: The contact URI as a string (e.g., “sip:bob@192.168.1.2:5060”)display_name
: Optional display name (e.g., “Bob”)
§Returns
Self for method chaining
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::StatusCode;
let builder = SimpleResponseBuilder::new(StatusCode::Ok, None)
.contact("sip:bob@192.168.1.2:5060", Some("Bob"));
Sourcepub fn content_type(self, content_type: &str) -> Self
pub fn content_type(self, content_type: &str) -> Self
Add a Content-Type header
Creates and adds a Content-Type header as specified in RFC 3261 Section 20.15. The Content-Type header indicates the media type of the message body.
§Parameters
content_type
: The content type (e.g., “application/sdp”)
§Returns
Self for method chaining
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::StatusCode;
let builder = SimpleResponseBuilder::new(StatusCode::Ok, None)
.content_type("application/sdp");
Sourcepub fn header(self, header: TypedHeader) -> Self
pub fn header(self, header: TypedHeader) -> Self
Add a generic header
Allows adding any supported SIP header type using the TypedHeader
enum.
This is useful for headers that don’t have a dedicated method in the builder.
§Parameters
header
: The typed header to add
§Returns
Self for method chaining
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{StatusCode, TypedHeader};
use rvoip_sip_core::types::server::ServerInfo;
// Create a vector of server product tokens
let server_products = vec!["SIPCore/2.1".to_string(), "(High Performance Edition)".to_string()];
let builder = SimpleResponseBuilder::new(StatusCode::Ok, None)
.header(TypedHeader::Server(server_products));
Sourcepub fn body(self, body: impl Into<Bytes>) -> Self
pub fn body(self, body: impl Into<Bytes>) -> Self
Add body content and update Content-Length
Adds a message body to the response and automatically sets the Content-Length header as specified in RFC 3261 Section 20.14.
§Parameters
body
: The body content (e.g., SDP for session description)
§Returns
Self for method chaining
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::StatusCode;
use rvoip_sip_core::sdp::SdpBuilder;
use rvoip_sip_core::sdp::attributes::MediaDirection;
// Create an SDP body using the SdpBuilder pattern
let sdp_body = SdpBuilder::new("Session")
.origin("bob", "2890844527", "2890844527", "IN", "IP4", "127.0.0.1")
.connection("IN", "IP4", "127.0.0.1")
.time("0", "0")
.media_audio(49172, "RTP/AVP")
.formats(&["0"])
.rtpmap("0", "PCMU/8000")
.done()
.build()
.expect("Valid SDP");
let builder = SimpleResponseBuilder::new(StatusCode::Ok, None)
.content_type("application/sdp")
.body(sdp_body.to_string());
Sourcepub fn build(self) -> Response
pub fn build(self) -> Response
Build the final Response
Finalizes the response construction and returns the complete SIP response.
§Returns
The constructed Response
§Example
use rvoip_sip_core::builder::SimpleResponseBuilder;
use rvoip_sip_core::types::{StatusCode, Method};
let response = SimpleResponseBuilder::new(StatusCode::Ok, None)
.from("Alice", "sip:alice@example.com", Some("1928301774"))
.to("Bob", "sip:bob@example.com", Some("a6c85cf"))
.call_id("a84b4c76e66710")
.cseq(1, Method::Invite)
.via("example.com", "UDP", Some("z9hG4bK776asdhds"))
.build();
Trait Implementations§
Source§impl CallIdBuilderExt for SimpleResponseBuilder
impl CallIdBuilderExt for SimpleResponseBuilder
Source§fn random_call_id(self) -> Self
fn random_call_id(self) -> Self
Source§fn random_call_id_with_host(self, host: &str) -> Self
fn random_call_id_with_host(self, host: &str) -> Self
Source§impl CallInfoBuilderExt for SimpleResponseBuilder
impl CallInfoBuilderExt for SimpleResponseBuilder
Source§fn call_info_uri(self, uri: &str, purpose: Option<&str>) -> Self
fn call_info_uri(self, uri: &str, purpose: Option<&str>) -> Self
Source§fn call_info_value(self, value: CallInfoValue) -> Self
fn call_info_value(self, value: CallInfoValue) -> Self
Source§fn call_info_values(self, values: Vec<CallInfoValue>) -> Self
fn call_info_values(self, values: Vec<CallInfoValue>) -> Self
Source§impl ContentBuilderExt for SimpleResponseBuilder
Implementation for new SimpleResponseBuilder
impl ContentBuilderExt for SimpleResponseBuilder
Implementation for new SimpleResponseBuilder
Source§fn sdp_body(self, sdp: &SdpSession) -> Self
fn sdp_body(self, sdp: &SdpSession) -> Self
Source§impl ContentLengthBuilderExt for SimpleResponseBuilder
impl ContentLengthBuilderExt for SimpleResponseBuilder
Source§fn content_length(self, length: u32) -> Self
fn content_length(self, length: u32) -> Self
Source§fn no_content(self) -> Self
fn no_content(self) -> Self
Source§impl ContentTypeBuilderExt for SimpleResponseBuilder
impl ContentTypeBuilderExt for SimpleResponseBuilder
Source§fn content_type_sdp(self) -> Self
fn content_type_sdp(self) -> Self
Source§fn content_type_text(self) -> Self
fn content_type_text(self) -> Self
Source§fn content_type_xml(self) -> Self
fn content_type_xml(self) -> Self
Source§fn content_type_json(self) -> Self
fn content_type_json(self) -> Self
Source§fn content_type_sipfrag(self) -> Self
fn content_type_sipfrag(self) -> Self
Source§fn content_type_custom(self, media_type: &str, media_subtype: &str) -> Self
fn content_type_custom(self, media_type: &str, media_subtype: &str) -> Self
Source§fn content_type(self, content_type: &str) -> Self
fn content_type(self, content_type: &str) -> Self
Source§impl HeaderSetter for SimpleResponseBuilder
impl HeaderSetter for SimpleResponseBuilder
Source§fn set_header<H: TypedHeaderTrait + 'static>(self, header: H) -> Self
fn set_header<H: TypedHeaderTrait + 'static>(self, header: H) -> Self
Source§impl MaxForwardsBuilderExt for SimpleResponseBuilder
impl MaxForwardsBuilderExt for SimpleResponseBuilder
Source§fn max_forwards(self, value: u32) -> Self
fn max_forwards(self, value: u32) -> Self
Source§impl MimeVersionBuilderExt for SimpleResponseBuilder
impl MimeVersionBuilderExt for SimpleResponseBuilder
Source§fn mime_version_1_0(self) -> Self
fn mime_version_1_0(self) -> Self
Source§impl RouteBuilderExt for ResponseBuilder
impl RouteBuilderExt for ResponseBuilder
Source§fn route_address(self, address: Address) -> Self
fn route_address(self, address: Address) -> Self
Source§fn route_entry(self, entry: RouteEntry) -> Self
fn route_entry(self, entry: RouteEntry) -> Self
Source§fn route_entries(self, entries: Vec<RouteEntry>) -> Self
fn route_entries(self, entries: Vec<RouteEntry>) -> Self
Source§impl ToBuilderExt for SimpleResponseBuilder
impl ToBuilderExt for SimpleResponseBuilder
Auto Trait Implementations§
impl !Freeze for SimpleResponseBuilder
impl RefUnwindSafe for SimpleResponseBuilder
impl Send for SimpleResponseBuilder
impl Sync for SimpleResponseBuilder
impl Unpin for SimpleResponseBuilder
impl UnwindSafe for SimpleResponseBuilder
Blanket Implementations§
Source§impl<T> AcceptEncodingExt for Twhere
T: HeaderSetter,
impl<T> AcceptEncodingExt for Twhere
T: HeaderSetter,
Source§impl<T> AcceptExt for Twhere
T: HeaderSetter,
impl<T> AcceptExt for Twhere
T: HeaderSetter,
Source§impl<T> AcceptLanguageExt for Twhere
T: HeaderSetter,
impl<T> AcceptLanguageExt for Twhere
T: HeaderSetter,
Source§impl<T> AlertInfoBuilderExt for Twhere
T: HeaderSetter,
impl<T> AlertInfoBuilderExt for Twhere
T: HeaderSetter,
Source§fn alert_info(self, uri: Uri) -> T
fn alert_info(self, uri: Uri) -> T
Source§fn alert_info_uri(self, uri_str: &str) -> T
fn alert_info_uri(self, uri_str: &str) -> T
Source§fn alert_info_with_param(
self,
uri: Uri,
param_name: &str,
param_value: &str,
) -> T
fn alert_info_with_param( self, uri: Uri, param_name: &str, param_value: &str, ) -> T
Source§impl<T> AllowBuilderExt for Twhere
T: HeaderSetter,
impl<T> AllowBuilderExt for Twhere
T: HeaderSetter,
Source§fn allow_method(self, method: Method) -> T
fn allow_method(self, method: Method) -> T
Source§fn allow_methods(self, methods: Vec<Method>) -> T
fn allow_methods(self, methods: Vec<Method>) -> T
Source§fn allow_standard_methods(self) -> T
fn allow_standard_methods(self) -> T
Source§fn allow_all_methods(self) -> T
fn allow_all_methods(self) -> T
Source§impl<T> AuthenticationInfoExt for Twhere
T: HeaderSetter,
impl<T> AuthenticationInfoExt for Twhere
T: HeaderSetter,
Source§impl<T> AuthorizationExt for Twhere
T: HeaderSetter,
impl<T> AuthorizationExt for Twhere
T: HeaderSetter,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ContentDispositionExt for Twhere
T: HeaderSetter,
impl<T> ContentDispositionExt for Twhere
T: HeaderSetter,
Source§fn content_disposition_session(self, handling: &str) -> T
fn content_disposition_session(self, handling: &str) -> T
Source§fn content_disposition_render(self, handling: &str) -> T
fn content_disposition_render(self, handling: &str) -> T
Source§fn content_disposition_icon(self, size: &str) -> T
fn content_disposition_icon(self, size: &str) -> T
Source§impl<T> ContentEncodingExt for Twhere
T: HeaderSetter,
impl<T> ContentEncodingExt for Twhere
T: HeaderSetter,
Source§impl<T> ContentLanguageExt for Twhere
T: HeaderSetter,
impl<T> ContentLanguageExt for Twhere
T: HeaderSetter,
Source§impl<T> ErrorInfoBuilderExt for Twhere
T: HeaderSetter,
impl<T> ErrorInfoBuilderExt for Twhere
T: HeaderSetter,
Source§fn error_info_uri(self, uri: &str) -> T
fn error_info_uri(self, uri: &str) -> T
Source§fn error_info_uri_with_param(
self,
uri: &str,
param_name: &str,
param_value: &str,
) -> T
fn error_info_uri_with_param( self, uri: &str, param_name: &str, param_value: &str, ) -> T
Source§fn error_info_uri_with_params(self, uri: &str, params: Vec<(&str, &str)>) -> T
fn error_info_uri_with_params(self, uri: &str, params: Vec<(&str, &str)>) -> T
Source§impl<T> EventBuilderExt for Twhere
T: HeaderSetter,
impl<T> EventBuilderExt for Twhere
T: HeaderSetter,
Source§fn event(self, event_data: Event) -> T
fn event(self, event_data: Event) -> T
Event
object. Read moreSource§fn event_type(self, event_type: EventType) -> T
fn event_type(self, event_type: EventType) -> T
id
or other parameters. Read moreSource§fn event_id(self, event_type: EventType, id: impl Into<String>) -> T
fn event_id(self, event_type: EventType, id: impl Into<String>) -> T
id
parameter. Read moreSource§fn event_full(
self,
event_type: EventType,
id: Option<impl Into<String>>,
params_vec: Vec<(impl Into<String>, Option<impl Into<String>>)>,
) -> T
fn event_full( self, event_type: EventType, id: Option<impl Into<String>>, params_vec: Vec<(impl Into<String>, Option<impl Into<String>>)>, ) -> T
id
, and generic parameters. Read more