diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 3859754..2d1d20a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ use core::fmt; use std::{ borrow::Cow, collections::HashMap, + fmt::format, io::{self, BufRead, BufReader, BufWriter, Write}, net::{IpAddr, SocketAddr}, path::PathBuf, @@ -183,6 +184,7 @@ async fn form_response<'req>( Err(e) => return e, Ok(None) | Ok(Some("text/plain")) => ContentType::Plain, Ok(Some("application/json")) => ContentType::Json, + Ok(Some("application/xml")) | Ok(Some("text/xml")) => ContentType::Xml, Ok(Some(_)) => return error(415, "unsupported content-type"), }; @@ -266,6 +268,9 @@ fn make_ip_response(requested_type: ContentType, response: Response) -> Vec<u8> let body = match requested_type { ContentType::Plain => format!("{client_addr}"), ContentType::Json => format!(r#"{{"ip": "{client_addr}"}}"#), + ContentType::Xml => { + format!("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ip>{client_addr}</ip>") + } }; let length = body.len(); @@ -457,6 +462,7 @@ impl Database { enum ContentType { Plain, Json, + Xml, } impl fmt::Display for ContentType { @@ -464,6 +470,7 @@ impl fmt::Display for ContentType { match self { ContentType::Plain => write!(f, "text/plain"), ContentType::Json => write!(f, "application/json"), + ContentType::Xml => write!(f, "application/xml"), } } } |