LGYUP7U5UX7MOJGEMUD2UDAZZXAMJOE7GO5DEI5HVYAATG3SCIPQC /// Create a 200 OK response with application/octet-stream.pub fn ok_bin(data: Vec<u8>) -> HttpResponse {Response::from_data(data).with_status_code(StatusCode(200)).with_header(Header::from_bytes("Content-Type", "application/octet-stream").unwrap())
macro_rules! header {($name:expr, $value:expr) => {tiny_http::Header::from_bytes(&$name.as_bytes()[..], &$value.as_bytes()[..]).expect("Header should be created from bytes")};
/// Create a 200 OK response with text/plain.pub fn ok_text(s: String) -> HttpResponse {Response::from_data(s).with_status_code(StatusCode(200)).with_header(Header::from_bytes("Content-Type", "text/plain").unwrap())
/// Create a 200 OK response with application/octet-stream.pub fn binary(d: Vec<u8>) -> HttpResponse {Response::from_data(d).with_header(header!("Content-Type", "application/octet-stream"))
pub fn ok_json(s: &str) -> HttpResponse {Response::from_string(s).with_status_code(StatusCode(200)).with_header(Header::from_bytes("Content-Type", "application/json").unwrap())}/// Create a 400 Bad Request response.pub fn bad_request() -> HttpResponse {Response::from_string("bad request\n").with_status_code(StatusCode(400))
pub fn json(s: &str) -> HttpResponse {Response::from_string(s).with_header(header!("Content-Type", "application/json"))
/// Create a 404 Not Found response with a message.////// Returned when:/// - Requested change/tag file doesn't exist/// - Channel doesn't exist/// - Path doesn't start with `.pijul`/// - Hash validation failspub fn not_found(msg: &str) -> HttpResponse {Response::from_string(format!("{msg}\n")).with_status_code(StatusCode(404))}
/// Return status code with default reason phrasepub fn status_code(code: u16) -> HttpResponse {let c = StatusCode::from(code);
.with_status_code(StatusCode(200)).with_header(Header::from_bytes("Content-Type", content_type).unwrap()).with_header(Header::from_bytes("Cache-Control", "public, max-age=31536000, immutable").unwrap(),),Err(_) => not_found("not found"),
.with_header(header!("Content-Type", content_type)).with_header(header!("Cache-Control","public, max-age=31536000, immutable")),Err(_) => status_code(404),
Some((pos, merkle, tag_merkle)) => ok_text(format!("{} {} {}", pos, merkle, tag_merkle)),None => ok_text("-".to_string()), // Spec says return "-" if not found
Some((pos, merkle, tag_merkle)) => Response::from_string(format!("{} {} {}", pos, merkle, tag_merkle)),None => responses::status_code(400)