pillow_http/
body.rs

1use serde_json::Value;
2
3/// Body of http
4#[derive(Debug, Clone, PartialEq)]
5pub enum Body {
6    /// Json format
7    JSON(Value),
8
9    /// XML format
10    XML(String),
11
12    /// HTML format
13    HTML(String),
14
15    /// For other formats
16    NONE,
17}
18
19/// Convert a string in Body enum
20pub fn from_string_to_body(string: String) -> Body {
21    let string = string.trim().to_string();
22
23    if string.starts_with("<html>") {
24        Body::HTML(string)
25    } else if string.starts_with("{") {
26        let json = serde_json::from_str(string.as_str()).unwrap();
27
28        Body::JSON(json)
29    } else if string.starts_with("<") {
30        Body::XML(string)
31    } else {
32        Body::NONE
33    }
34}