diff options
Diffstat (limited to 'src/encoding/response.rs')
-rw-r--r-- | src/encoding/response.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/encoding/response.rs b/src/encoding/response.rs index 3564b34..7ee124f 100644 --- a/src/encoding/response.rs +++ b/src/encoding/response.rs @@ -1,10 +1,10 @@ -use super::headermap::HeaderMap; +use super::{headermap::HeaderMap, status::Status}; use anyhow::{anyhow, bail, Context}; -use std::str::FromStr; +use std::{fmt::Display, str::FromStr}; #[derive(Debug)] pub struct Response { - pub code: u16, + pub status: Status, pub headers: HeaderMap, } @@ -35,6 +35,15 @@ impl FromStr for Response { headers.insert_raw(key.trim().to_string(), value.trim().to_string()) } - Ok(Self { code, headers }) + let status = Status::from_code(code); + Ok(Self { status, headers }) + } +} +impl Display for Response { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { status, headers } = self; + write!(f, "SIP/2.0 {} {status:?}\r\n", status.to_code())?; + write!(f, "{headers}\r\n")?; + Ok(()) } } |