pub fn parse_body(
    logs: &mut Logs,
    args: &mut RequestField,
    max_depth: usize,
    mcontent_type: Option<&str>,
    accepted_types: &[ContentType],
    body: &[u8],
) -> Result<(), String> {
    logs.debug("body parsing started");
    if max_depth == 0 {
        logs.warning("max_depth is 0, body parsing avoided");
        return Ok(());
    }

    let active_accepted_types = if accepted_types.is_empty() {
        &ContentType::VALUES
    } else {
        accepted_types
    };

    if let Some(content_type) = mcontent_type {
        for t in active_accepted_types {
            match t {
                ContentType::Graphql => {
                    if content_type == "application/graphql" {
                        return graphql::graphql_body(max_depth, args, body);
                    }
                }
                ContentType::Json => {
                    if content_type.ends_with("/json") {
                        return json_body(max_depth, args, body);
                    }
                }
                ContentType::MultipartForm => {
                    if let Some(boundary) = content_type.strip_prefix("multipart/form-data; boundary=") {
                        return multipart_form_encoded(boundary, args, body);
                    }
                }
                ContentType::Xml => {
                    if content_type.ends_with("/xml") {
                        return xml_body(max_depth, args, body);
                    }
                }
                ContentType::UrlEncoded => {
                    if content_type == "application/x-www-form-urlencoded" {
                        return forms_body(args, body);
                    }
                }
            }
        }
    }

    logs.debug("content-type based body parsing failed");

    // content-type not found
    if accepted_types.is_empty() {
        // we had no particular expection, so blindly try json, and urlencoded
        json_body(max_depth, args, body).or_else(|_| forms_body(args, body))
    } else {
        // we expected a specific content type!
        Err(format!(
            "Invalid content type={:?}, accepted types={:?}",
            mcontent_type, accepted_types
        ))
    }
}
/// body parsing function, returns an error when the body can't be decoded
body parsing function, returns an error when the body can't be decoded
body parsing function returns an error when the body can ' t be decoded
pub fn parse_body(
    logs: &mut Logs,
    args: &mut RequestField,
    max_depth: usize,
    mcontent_type: Option<&str>,
    accepted_types: &[ContentType],
    body: &[u8],
) -> Result<(), String> {
    logs.debug("body parsing started");
    if max_depth == 0 {
        logs.warning("max_depth is 0, body parsing avoided");
        return Ok(());
    }
    let active_accepted_types = if accepted_types.is_empty() {
        &ContentType::VALUES
    } else {
        accepted_types
    };
    if let Some(content_type) = mcontent_type {
        for t in active_accepted_types {
            match t {
                ContentType::Graphql => {
                    if content_type == "application/graphql" {
                        return graphql::graphql_body(max_depth, args, body);
                    }
                }
                ContentType::Json => {
                    if content_type.ends_with("/json") {
                        return json_body(max_depth, args, body);
                    }
                }
                ContentType::MultipartForm => {
                    if let Some(boundary) = content_type.strip_prefix("multipart/form-data; boundary=") {
                        return multipart_form_encoded(boundary, args, body);
                    }
                }
                ContentType::Xml => {
                    if content_type.ends_with("/xml") {
                        return xml_body(max_depth, args, body);
                    }
                }
                ContentType::UrlEncoded => {
                    if content_type == "application/x-www-form-urlencoded" {
                        return forms_body(args, body);
                    }
                }
            }
        }
    }
    logs.debug("content-type based body parsing failed");
    // content-type not found
    if accepted_types.is_empty() {
        // we had no particular expection, so blindly try json, and urlencoded
        json_body(max_depth, args, body).or_else(|_| forms_body(args, body))
    } else {
        // we expected a specific content type!
        Err(format!(
            "Invalid content type={:?}, accepted types={:?}",
            mcontent_type, accepted_types
        ))
    }
}
pub fn parse_body ( logs : & mut Logs , args : & mut RequestField , max_depth : usize , mcontent_type : Option < & str > , accepted_types : & [ ContentType ] , body : & [ u8 ] , ) -> Result < ( ) , String > { logs . debug ( " " ) ; if max_depth == 0 { logs . warning ( " " ) ; return Ok ( ( ) ) ; } let active_accepted_types = if accepted_types . is_empty ( ) { & ContentType :: VALUES } else { accepted_types } ; if let Some ( content_type ) = mcontent_type { for t in active_accepted_types { match t { ContentType :: Graphql => { if content_type == " " { return graphql :: graphql_body ( max_depth , args , body ) ; } } ContentType :: Json => { if content_type . ends_with ( " " ) { return json_body ( max_depth , args , body ) ; } } ContentType :: MultipartForm => { if let Some ( boundary ) = content_type . strip_prefix ( " " ) { return multipart_form_encoded ( boundary , args , body ) ; } } ContentType :: Xml => { if content_type . ends_with ( " " ) { return xml_body ( max_depth , args , body ) ; } } ContentType :: UrlEncoded => { if content_type == " " { return forms_body ( args , body ) ; } } } } } logs . debug ( " " ) ; // content-type not found if accepted_types . is_empty ( ) { // we had no particular expection, so blindly try json, and urlencoded json_body ( max_depth , args , body ) . or_else ( | _ | forms_body ( args , body ) ) } else { // we expected a specific content type! Err ( format ! ( " " mcontent_type accepted_types ) ) } }
body parsing function, returns an error when the body can't be decoded
body parsing function returns an error when the body can ' t be decoded
logs
&mut Logs
args
&mut RequestField
max_depth
usize
mcontent_type
Option<&str>
accepted_types
&[ContentType]
body
&[u8]