Make build work (#546)
The mbedtls example has caused problem in the main build a number of times. By making it a standalone `cargo new --bin`, we can keep it in the source tree as a good example but avoid having it break the main build. Also, fix some clippy lints.
This commit is contained in:
@@ -50,7 +50,6 @@ serde = { version = "1", features = ["derive"] }
|
||||
env_logger = "0.9"
|
||||
rustls = { version = "0.20", features = ["dangerous_configuration"] }
|
||||
rustls-pemfile = { version = "1.0" }
|
||||
mbedtls = { version = "0.8.1" }
|
||||
|
||||
[[example]]
|
||||
name = "cureq"
|
||||
|
||||
8
examples/mbedtls/Cargo.toml
Normal file
8
examples/mbedtls/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "mbedtls-example"
|
||||
version = "0.0.1"
|
||||
edition = "2021"
|
||||
|
||||
|
||||
[dependencies]
|
||||
mbedtls = { version = "0.8.1" }
|
||||
9
examples/mbedtls/README.md
Normal file
9
examples/mbedtls/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
mbedtls-example
|
||||
===============
|
||||
|
||||
To run this example you need to `cd` into the directory and use `cargo run`.
|
||||
|
||||
```
|
||||
cd ureq/exampled/mbedtls
|
||||
cargo run
|
||||
```
|
||||
@@ -5,7 +5,6 @@ use std::time::Duration;
|
||||
use std::{env, error, fmt, result};
|
||||
|
||||
use log::{error, info};
|
||||
use ureq;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Oops(String);
|
||||
@@ -77,7 +76,7 @@ fn get_many(urls: Vec<String>, simultaneous_fetches: usize) -> Result<()> {
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = env::args();
|
||||
let mut args = env::args();
|
||||
if args.len() == 1 {
|
||||
println!(
|
||||
r##"Usage: {:#?} top-1m.csv
|
||||
@@ -94,11 +93,11 @@ using 50 threads concurrently.
|
||||
return Ok(());
|
||||
}
|
||||
env_logger::init();
|
||||
let file = std::fs::File::open(args.skip(1).next().unwrap())?;
|
||||
let file = std::fs::File::open(args.nth(1).unwrap())?;
|
||||
let bufreader = BufReader::new(file);
|
||||
let mut urls = vec![];
|
||||
for line in bufreader.lines() {
|
||||
let domain = line?.rsplit(",").next().unwrap().to_string();
|
||||
let domain = line?.rsplit(',').next().unwrap().to_string();
|
||||
urls.push(format!("http://{}/", domain));
|
||||
urls.push(format!("https://{}/", domain));
|
||||
urls.push(format!("http://www.{}/", domain));
|
||||
|
||||
@@ -328,7 +328,7 @@ impl Error {
|
||||
}
|
||||
|
||||
/// One of the types of error the can occur when processing a Request.
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum ErrorKind {
|
||||
/// The url could not be understood.
|
||||
InvalidUrl,
|
||||
|
||||
@@ -62,7 +62,7 @@ impl fmt::Display for HeaderLine {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
/// Wrapper type for a header field.
|
||||
/// <https://tools.ietf.org/html/rfc7230#section-3.2>
|
||||
pub struct Header {
|
||||
|
||||
@@ -799,9 +799,9 @@ pub(crate) fn charset_from_content_type(header: Option<&str>) -> &str {
|
||||
header
|
||||
.and_then(|header| {
|
||||
header.find(';').and_then(|semi| {
|
||||
(&header[semi + 1..])
|
||||
header[semi + 1..]
|
||||
.find('=')
|
||||
.map(|equal| (&header[semi + equal + 2..]).trim())
|
||||
.map(|equal| header[semi + equal + 2..].trim())
|
||||
})
|
||||
})
|
||||
.unwrap_or(DEFAULT_CHARACTER_SET)
|
||||
|
||||
@@ -666,7 +666,7 @@ mod tests {
|
||||
let mut deadline_stream = DeadlineStream::new(stream, None);
|
||||
let mut buf = [0u8; 1];
|
||||
for _ in 0..8193 {
|
||||
deadline_stream.read(&mut buf).unwrap();
|
||||
let _ = deadline_stream.read(&mut buf).unwrap();
|
||||
}
|
||||
let reads = reads.lock().unwrap();
|
||||
assert_eq!(reads.len(), 2);
|
||||
|
||||
@@ -80,7 +80,7 @@ fn connection_reuse_with_408() {
|
||||
// pulls from the pool. If for some reason the timed-out
|
||||
// connection wasn't in the pool, we won't be testing what
|
||||
// we thought we were testing.
|
||||
let resp = agent.post(&url).send_string("hello".into()).unwrap();
|
||||
let resp = agent.post(&url).send_string("hello").unwrap();
|
||||
assert_eq!(resp.status(), 200);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ mod timeout;
|
||||
|
||||
type RequestHandler = dyn Fn(&Unit) -> Result<Stream, Error> + Send + 'static;
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub(crate) static TEST_HANDLERS: Lazy<Arc<Mutex<HashMap<String, Box<RequestHandler>>>>> =
|
||||
Lazy::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user