From 208aa2791d45927bcd2cfe3d11111b26d8f5703c Mon Sep 17 00:00:00 2001 From: gennyble Date: Mon, 16 Jun 2025 22:02:13 -0500 Subject: support xml response type --- src/main.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main.rs') 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 let body = match requested_type { ContentType::Plain => format!("{client_addr}"), ContentType::Json => format!(r#"{{"ip": "{client_addr}"}}"#), + ContentType::Xml => { + format!("\n{client_addr}") + } }; 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"), } } } -- cgit 1.4.1-3-g733a5