pub fn curl_args(&self, context_dir: String) -> Vec<String> {
        let querystring = if self.querystring.is_empty() {
            "".to_string()
        } else {
            let params = self
                .querystring
                .iter()
                .map(|p| p.curl_arg_escape())
                .collect::<Vec<String>>();
            params.join("&")
        };
        let url = if querystring.as_str() == "" {
            self.url.to_string()
        } else if self.url.to_string().contains('?') {
            format!("{}&{}", self.url.to_string(), querystring)
        } else {
            format!("{}?{}", self.url.to_string(), querystring)
        };
        let mut arguments = vec![format!("'{}'", url)];

        let data =
            !self.multipart.is_empty() || !self.form.is_empty() || !self.body.bytes().is_empty();
        arguments.append(&mut self.method.curl_args(data));

        for header in self.headers.clone() {
            arguments.append(&mut header.curl_args());
        }

        let has_explicit_content_type = self
            .headers
            .iter()
            .map(|h| h.name.clone())
            .any(|n| n.as_str() == "Content-Type");
        if !has_explicit_content_type {
            if let Some(content_type) = self.content_type.clone() {
                if content_type.as_str() != "application/x-www-form-urlencoded"
                    && content_type.as_str() != "multipart/form-data"
                {
                    arguments.push("-H".to_string());
                    arguments.push(format!("'Content-Type: {}'", content_type));
                }
            } else if !self.body.bytes().is_empty() {
                match self.body.clone() {
                    Body::Text(_) => {
                        arguments.push("-H".to_string());
                        arguments.push("'Content-Type:'".to_string())
                    }
                    Body::Binary(_) => {
                        arguments.push("-H".to_string());
                        arguments.push("'Content-Type: application/octet-stream'".to_string())
                    }
                    Body::File(_, _) => {
                        arguments.push("-H".to_string());
                        arguments.push("'Content-Type:'".to_string())
                    }
                }
            }
        }

        for param in self.form.clone() {
            arguments.push("--data".to_string());
            arguments.push(format!("'{}'", param.curl_arg_escape()));
        }
        for param in self.multipart.clone() {
            arguments.push("-F".to_string());
            arguments.push(format!("'{}'", param.curl_arg(context_dir.clone())));
        }

        if !self.body.bytes().is_empty() {
            arguments.push("--data".to_string());
            match self.body.clone() {
                Body::Text(s) => {
                    let prefix = if s.contains('\n') { "$" } else { "" };
                    arguments.push(format!(
                        "{}'{}'",
                        prefix,
                        s.replace("\\", "\\\\").replace("\n", "\\n")
                    ))
                }
                Body::Binary(bytes) => arguments.push(format!("$'{}'", encode_bytes(bytes))),
                Body::File(_, filename) => {
                    let prefix = if context_dir.as_str() == "." {
                        "".to_string()
                    } else {
                        format!("{}/", context_dir)
                    };
                    arguments.push(format!("'@{}{}'", prefix, filename))
                }
            }
        }

        arguments
    }
///
/// return request as curl arguments
/// It does not contain the requests cookies (they will be accessed from the client)
///
return request as curl arguments
It does not contain the requests cookies (they will be accessed from the client)
return request as curl arguments It does not contain the requests cookies ( they will be accessed from the client )
pub fn curl_args(&self, context_dir: String) -> Vec<String> {
        let querystring = if self.querystring.is_empty() {
            "".to_string()
        } else {
            let params = self
                .querystring
                .iter()
                .map(|p| p.curl_arg_escape())
                .collect::<Vec<String>>();
            params.join("&")
        };
        let url = if querystring.as_str() == "" {
            self.url.to_string()
        } else if self.url.to_string().contains('?') {
            format!("{}&{}", self.url.to_string(), querystring)
        } else {
            format!("{}?{}", self.url.to_string(), querystring)
        };
        let mut arguments = vec![format!("'{}'", url)];
        let data =
            !self.multipart.is_empty() || !self.form.is_empty() || !self.body.bytes().is_empty();
        arguments.append(&mut self.method.curl_args(data));
        for header in self.headers.clone() {
            arguments.append(&mut header.curl_args());
        }
        let has_explicit_content_type = self
            .headers
            .iter()
            .map(|h| h.name.clone())
            .any(|n| n.as_str() == "Content-Type");
        if !has_explicit_content_type {
            if let Some(content_type) = self.content_type.clone() {
                if content_type.as_str() != "application/x-www-form-urlencoded"
                    && content_type.as_str() != "multipart/form-data"
                {
                    arguments.push("-H".to_string());
                    arguments.push(format!("'Content-Type: {}'", content_type));
                }
            } else if !self.body.bytes().is_empty() {
                match self.body.clone() {
                    Body::Text(_) => {
                        arguments.push("-H".to_string());
                        arguments.push("'Content-Type:'".to_string())
                    }
                    Body::Binary(_) => {
                        arguments.push("-H".to_string());
                        arguments.push("'Content-Type: application/octet-stream'".to_string())
                    }
                    Body::File(_, _) => {
                        arguments.push("-H".to_string());
                        arguments.push("'Content-Type:'".to_string())
                    }
                }
            }
        }
        for param in self.form.clone() {
            arguments.push("--data".to_string());
            arguments.push(format!("'{}'", param.curl_arg_escape()));
        }
        for param in self.multipart.clone() {
            arguments.push("-F".to_string());
            arguments.push(format!("'{}'", param.curl_arg(context_dir.clone())));
        }
        if !self.body.bytes().is_empty() {
            arguments.push("--data".to_string());
            match self.body.clone() {
                Body::Text(s) => {
                    let prefix = if s.contains('\n') { "$" } else { "" };
                    arguments.push(format!(
                        "{}'{}'",
                        prefix,
                        s.replace("\\", "\\\\").replace("\n", "\\n")
                    ))
                }
                Body::Binary(bytes) => arguments.push(format!("$'{}'", encode_bytes(bytes))),
                Body::File(_, filename) => {
                    let prefix = if context_dir.as_str() == "." {
                        "".to_string()
                    } else {
                        format!("{}/", context_dir)
                    };
                    arguments.push(format!("'@{}{}'", prefix, filename))
                }
            }
        }
        arguments
    }
pub fn curl_args ( & self , context_dir : String ) -> Vec < String > { let querystring = if self . querystring . is_empty ( ) { " " . to_string ( ) } else { let params = self . querystring . iter ( ) . map ( | p | p . curl_arg_escape ( ) ) . collect :: < Vec < String > > ( ) ; params . join ( " " ) } ; let url = if querystring . as_str ( ) == " " { self . url . to_string ( ) } else if self . url . to_string ( ) . contains ( '?' ) { format ! ( " " self url to_string ( ) querystring ) } else { format ! ( " " self url to_string ( ) querystring ) } ; let mut arguments = vec ! [ format ( " " url ) ] ; let data = ! self . multipart . is_empty ( ) || ! self . form . is_empty ( ) || ! self . body . bytes ( ) . is_empty ( ) ; arguments . append ( & mut self . method . curl_args ( data ) ) ; for header in self . headers . clone ( ) { arguments . append ( & mut header . curl_args ( ) ) ; } let has_explicit_content_type = self . headers . iter ( ) . map ( | h | h . name . clone ( ) ) . any ( | n | n . as_str ( ) == " " ) ; if ! has_explicit_content_type { if let Some ( content_type ) = self . content_type . clone ( ) { if content_type . as_str ( ) != " " && content_type . as_str ( ) != " " { arguments . push ( " " . to_string ( ) ) ; arguments . push ( format ! ( " " content_type ) ) ; } } else if ! self . body . bytes ( ) . is_empty ( ) { match self . body . clone ( ) { Body :: Text ( _ ) => { arguments . push ( " " . to_string ( ) ) ; arguments . push ( " " . to_string ( ) ) } Body :: Binary ( _ ) => { arguments . push ( " " . to_string ( ) ) ; arguments . push ( " " . to_string ( ) ) } Body :: File ( _ , _ ) => { arguments . push ( " " . to_string ( ) ) ; arguments . push ( " " . to_string ( ) ) } } } } for param in self . form . clone ( ) { arguments . push ( " " . to_string ( ) ) ; arguments . push ( format ! ( " " param curl_arg_escape ( ) ) ) ; } for param in self . multipart . clone ( ) { arguments . push ( " " . to_string ( ) ) ; arguments . push ( format ! ( " " param curl_arg ( context_dir clone ( ) ) ) ) ; } if ! self . body . bytes ( ) . is_empty ( ) { arguments . push ( " " . to_string ( ) ) ; match self . body . clone ( ) { Body :: Text ( s ) => { let prefix = if s . contains ( '\n' ) { " " } else { " " } ; arguments . push ( format ! ( " " prefix s replace ( " \\ " " \\ \\ " ) replace ( " \n " " \\ " ) ) ) } Body :: Binary ( bytes ) => arguments . push ( format ! ( " " encode_bytes ( bytes ) ) ) , Body :: File ( _ , filename ) => { let prefix = if context_dir . as_str ( ) == " " { " " . to_string ( ) } else { format ! ( " " context_dir ) } ; arguments . push ( format ! ( " " prefix filename ) ) } } } arguments }
return request as curl arguments
It does not contain the requests cookies (they will be accessed from the client)
return request as curl arguments It does not contain the requests cookies ( they will be accessed from the client )
&self
context_dir
String
&self
context_dir
String