remove util submod

This commit is contained in:
Martin Algesten
2018-06-14 15:18:01 +02:00
parent 75c8a9bbde
commit f2c3f351ca
5 changed files with 25 additions and 32 deletions

View File

@@ -3,7 +3,6 @@ use std::str::FromStr;
use std::sync::Mutex; use std::sync::Mutex;
use header::{add_header, Header}; use header::{add_header, Header};
use util::*;
// to get to share private fields // to get to share private fields
include!("request.rs"); include!("request.rs");
@@ -270,6 +269,29 @@ impl Agent {
} }
} }
fn basic_auth(user: &str, pass: &str) -> String {
let safe = match user.find(":") {
Some(idx) => &user[..idx],
None => user,
};
::base64::encode(&format!("{}:{}", safe, pass))
}
fn mime_of<S: Into<String>>(s: S) -> String {
let s = s.into();
match &s[..] {
"json" => "application/json",
"form" => "application/x-www-form-urlencoded",
_ => match ::mime_guess::get_mime_type_str(&s) {
Some(mime) => mime,
None => "foo",
},
}.to_string()
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@@ -12,11 +12,11 @@ extern crate serde_json;
extern crate native_tls; extern crate native_tls;
extern crate url; extern crate url;
#[macro_use]
mod agent; mod agent;
mod error; mod error;
mod header; mod header;
mod util; mod macros;
mod serde_macros;
#[cfg(test)] #[cfg(test)]
mod test; mod test;

View File

@@ -1,29 +0,0 @@
#[allow(dead_code)]
mod macros;
mod serde_macros;
pub mod vecread;
use base64;
use mime_guess::get_mime_type_str;
pub use util::vecread::VecRead;
pub fn basic_auth(user: &str, pass: &str) -> String {
let safe = match user.find(":") {
Some(idx) => &user[..idx],
None => user,
};
base64::encode(&format!("{}:{}", safe, pass))
}
pub fn mime_of<S: Into<String>>(s: S) -> String {
let s = s.into();
match &s[..] {
"json" => "application/json",
"form" => "application/x-www-form-urlencoded",
_ => match get_mime_type_str(&s) {
Some(mime) => mime,
None => "foo",
},
}.to_string()
}