pub async fn create_response(
        &self,
        request: &IncomingRequest,
        code: Code,
        reason: Option<BytesStr>,
    ) -> Result<OutgoingResponse> {
        assert_ne!(request.line.method, Method::ACK);

        let mut headers = Headers::with_capacity(5);

        headers.insert_type(&request.base_headers.top_via);
        headers.insert_type(&request.base_headers.from);
        headers.insert_type(&request.base_headers.to);
        headers.insert_type(&request.base_headers.call_id);
        headers.insert_type(&request.base_headers.cseq);

        if code == Code::TRYING {
            let _ = request.headers.clone_into(&mut headers, Name::TIMESTAMP);
        }

        let destination = match request.tp_info.transport.direction() {
            Direction::None => {
                if let Some(maddr) = request
                    .base_headers
                    .top_via
                    .params
                    .get_val("maddr")
                    .and_then(|maddr| maddr.parse::<IpAddr>().ok())
                {
                    // TODO maddr default port guessing (currently defaulting to 5060)
                    vec![SocketAddr::new(
                        maddr,
                        request.base_headers.top_via.sent_by.port.unwrap_or(5060),
                    )]
                } else if let Some(rport) = request
                    .base_headers
                    .top_via
                    .params
                    .get_val("rport")
                    .and_then(|rport| rport.parse::<u16>().ok())
                {
                    vec![SocketAddr::new(request.tp_info.source.ip(), rport)]
                } else {
                    let destination = self
                        .transports()
                        // TODO correctly guess default port
                        .resolve_host_port(
                            &request.base_headers.top_via.sent_by.host,
                            request.base_headers.top_via.sent_by.port.unwrap_or(5060),
                        )
                        .await?;

                    destination
                }
            }
            Direction::Outgoing(remote) | Direction::Incoming(remote) => {
                // Use the transport from the request, same remote addr
                vec![remote]
            }
        };

        Ok(OutgoingResponse {
            msg: Response {
                line: StatusLine {
                    code,
                    reason: reason.or_else(|| code.text().map(BytesStr::from_static)),
                },
                headers,
                body: Bytes::new(),
            },
            parts: OutgoingParts {
                transport: request.tp_info.transport.clone(),
                destination,
                buffer: Default::default(),
            },
        })
    }
/// Create a response to an incoming request with a given status code and optional reason
///
/// This is async as it may need to make a DNS lookup to calculate the response address
Create a response to an incoming request with a given status code and optional reason
This is async as it may need to make a DNS lookup to calculate the response address
Create a response to an incoming request with a given status code and optional reason This is async as it may need to make a DNS lookup to calculate the response address
pub async fn create_response(
        &self,
        request: &IncomingRequest,
        code: Code,
        reason: Option<BytesStr>,
    ) -> Result<OutgoingResponse> {
        assert_ne!(request.line.method, Method::ACK);
        let mut headers = Headers::with_capacity(5);
        headers.insert_type(&request.base_headers.top_via);
        headers.insert_type(&request.base_headers.from);
        headers.insert_type(&request.base_headers.to);
        headers.insert_type(&request.base_headers.call_id);
        headers.insert_type(&request.base_headers.cseq);
        if code == Code::TRYING {
            let _ = request.headers.clone_into(&mut headers, Name::TIMESTAMP);
        }
        let destination = match request.tp_info.transport.direction() {
            Direction::None => {
                if let Some(maddr) = request
                    .base_headers
                    .top_via
                    .params
                    .get_val("maddr")
                    .and_then(|maddr| maddr.parse::<IpAddr>().ok())
                {
                    // TODO maddr default port guessing (currently defaulting to 5060)
                    vec![SocketAddr::new(
                        maddr,
                        request.base_headers.top_via.sent_by.port.unwrap_or(5060),
                    )]
                } else if let Some(rport) = request
                    .base_headers
                    .top_via
                    .params
                    .get_val("rport")
                    .and_then(|rport| rport.parse::<u16>().ok())
                {
                    vec![SocketAddr::new(request.tp_info.source.ip(), rport)]
                } else {
                    let destination = self
                        .transports()
                        // TODO correctly guess default port
                        .resolve_host_port(
                            &request.base_headers.top_via.sent_by.host,
                            request.base_headers.top_via.sent_by.port.unwrap_or(5060),
                        )
                        .await?;
                    destination
                }
            }
            Direction::Outgoing(remote) | Direction::Incoming(remote) => {
                // Use the transport from the request, same remote addr
                vec![remote]
            }
        };
        Ok(OutgoingResponse {
            msg: Response {
                line: StatusLine {
                    code,
                    reason: reason.or_else(|| code.text().map(BytesStr::from_static)),
                },
                headers,
                body: Bytes::new(),
            },
            parts: OutgoingParts {
                transport: request.tp_info.transport.clone(),
                destination,
                buffer: Default::default(),
            },
        })
    }
pub async fn create_response ( & self , request : & IncomingRequest , code : Code , reason : Option < BytesStr > , ) -> Result < OutgoingResponse > { assert_ne ! ( request line method Method ACK ) ; let mut headers = Headers :: with_capacity ( 5 ) ; headers . insert_type ( & request . base_headers . top_via ) ; headers . insert_type ( & request . base_headers . from ) ; headers . insert_type ( & request . base_headers . to ) ; headers . insert_type ( & request . base_headers . call_id ) ; headers . insert_type ( & request . base_headers . cseq ) ; if code == Code :: TRYING { let _ = request . headers . clone_into ( & mut headers , Name :: TIMESTAMP ) ; } let destination = match request . tp_info . transport . direction ( ) { Direction :: None => { if let Some ( maddr ) = request . base_headers . top_via . params . get_val ( " " ) . and_then ( | maddr | maddr . parse :: < IpAddr > ( ) . ok ( ) ) { // TODO maddr default port guessing (currently defaulting to 5060) vec ! [ SocketAddr new ( maddr request base_headers top_via sent_by port unwrap_or ( 5060 ) ) ] } else if let Some ( rport ) = request . base_headers . top_via . params . get_val ( " " ) . and_then ( | rport | rport . parse :: < u16 > ( ) . ok ( ) ) { vec ! [ SocketAddr new ( request tp_info source ip ( ) rport ) ] } else { let destination = self . transports ( ) // TODO correctly guess default port . resolve_host_port ( & request . base_headers . top_via . sent_by . host , request . base_headers . top_via . sent_by . port . unwrap_or ( 5060 ) , ) . await ? ; destination } } Direction :: Outgoing ( remote ) | Direction :: Incoming ( remote ) => { // Use the transport from the request, same remote addr vec ! [ remote ] } } ; Ok ( OutgoingResponse { msg : Response { line : StatusLine { code , reason : reason . or_else ( | | code . text ( ) . map ( BytesStr :: from_static ) ) , } , headers , body : Bytes :: new ( ) , } , parts : OutgoingParts { transport : request . tp_info . transport . clone ( ) , destination , buffer : Default :: default ( ) , } , } ) }
Create a response to an incoming request with a given status code and optional reason
This is async as it may need to make a DNS lookup to calculate the response address
Create a response to an incoming request with a given status code and optional reason This is async as it may need to make a DNS lookup to calculate the response address
&self
request
&IncomingRequest
code
Code
reason
Option<BytesStr>