Fix clippy warnings
This commit is contained in:
@@ -288,6 +288,8 @@ pub enum ErrorKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ErrorKind {
|
impl ErrorKind {
|
||||||
|
#[allow(clippy::wrong_self_convention)]
|
||||||
|
#[allow(clippy::new_ret_no_self)]
|
||||||
pub(crate) fn new(self) -> Error {
|
pub(crate) fn new(self) -> Error {
|
||||||
Error::new(self, None)
|
Error::new(self, None)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![warn(clippy::all)]
|
#![warn(clippy::all)]
|
||||||
|
// new is just more readable than ..Default::default().
|
||||||
|
#![allow(clippy::new_without_default)]
|
||||||
|
// the matches! macro is obscure and not widely known.
|
||||||
|
#![allow(clippy::match_like_matches_macro)]
|
||||||
|
|
||||||
//! A simple, safe HTTP client.
|
//! A simple, safe HTTP client.
|
||||||
//!
|
//!
|
||||||
//! Ureq's first priority is being easy for you to use. It's great for
|
//! Ureq's first priority is being easy for you to use. It's great for
|
||||||
@@ -327,8 +332,7 @@ pub fn is_test(is: bool) -> bool {
|
|||||||
if is {
|
if is {
|
||||||
IS_TEST.store(true, Ordering::SeqCst);
|
IS_TEST.store(true, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
let x = IS_TEST.load(Ordering::SeqCst);
|
IS_TEST.load(Ordering::SeqCst)
|
||||||
x
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Agents are used to hold configuration and keep state between requests.
|
/// Agents are used to hold configuration and keep state between requests.
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ impl Proxy {
|
|||||||
match host {
|
match host {
|
||||||
Some(host) => {
|
Some(host) => {
|
||||||
let mut parts = host.as_ref().split(':').collect::<Vec<&str>>().into_iter();
|
let mut parts = host.as_ref().split(':').collect::<Vec<&str>>().into_iter();
|
||||||
let host = parts.next().ok_or(ErrorKind::InvalidProxyUrl.new())?;
|
let host = parts
|
||||||
|
.next()
|
||||||
|
.ok_or_else(|| ErrorKind::InvalidProxyUrl.new())?;
|
||||||
let port = parts.next();
|
let port = parts.next();
|
||||||
Ok((
|
Ok((
|
||||||
String::from(host),
|
String::from(host),
|
||||||
@@ -155,11 +157,11 @@ Proxy-Connection: Keep-Alive\r\n\
|
|||||||
let top_line = response_string
|
let top_line = response_string
|
||||||
.lines()
|
.lines()
|
||||||
.next()
|
.next()
|
||||||
.ok_or(ErrorKind::ProxyConnect.new())?;
|
.ok_or_else(|| ErrorKind::ProxyConnect.new())?;
|
||||||
let status_code = top_line
|
let status_code = top_line
|
||||||
.split_whitespace()
|
.split_whitespace()
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.ok_or(ErrorKind::ProxyConnect.new())?;
|
.ok_or_else(|| ErrorKind::ProxyConnect.new())?;
|
||||||
|
|
||||||
match status_code {
|
match status_code {
|
||||||
"200" => Ok(()),
|
"200" => Ok(()),
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ pub(crate) struct Stream {
|
|||||||
inner: BufReader<Inner>,
|
inner: BufReader<Inner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
enum Inner {
|
enum Inner {
|
||||||
Http(TcpStream),
|
Http(TcpStream),
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
|
|||||||
@@ -113,13 +113,8 @@ pub fn read_request(stream: &TcpStream) -> TestHeaders {
|
|||||||
// There's a risk stream is ended here, and fill_buf() would block.
|
// There's a risk stream is ended here, and fill_buf() would block.
|
||||||
stream.set_nonblocking(true).ok();
|
stream.set_nonblocking(true).ok();
|
||||||
let mut reader = BufReader::new(stream);
|
let mut reader = BufReader::new(stream);
|
||||||
loop {
|
while let Ok(buf) = reader.fill_buf() {
|
||||||
let amount = match reader.fill_buf() {
|
let amount = buf.len();
|
||||||
Ok(buf) => buf.len(),
|
|
||||||
Err(_) => {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if amount == 0 {
|
if amount == 0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -148,8 +143,7 @@ impl TestServer {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// before returning from new(), ensure the server is ready to accept connections
|
// before returning from new(), ensure the server is ready to accept connections
|
||||||
loop {
|
while let Err(e) = TcpStream::connect(format!("127.0.0.1:{}", port)) {
|
||||||
if let Err(e) = TcpStream::connect(format!("127.0.0.1:{}", port)) {
|
|
||||||
match e.kind() {
|
match e.kind() {
|
||||||
io::ErrorKind::ConnectionRefused => {
|
io::ErrorKind::ConnectionRefused => {
|
||||||
std::thread::sleep(Duration::from_millis(100));
|
std::thread::sleep(Duration::from_millis(100));
|
||||||
@@ -157,9 +151,6 @@ impl TestServer {
|
|||||||
}
|
}
|
||||||
_ => eprintln!("testserver: pre-connect with error {}", e),
|
_ => eprintln!("testserver: pre-connect with error {}", e),
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
TestServer {
|
TestServer {
|
||||||
port,
|
port,
|
||||||
@@ -172,9 +163,8 @@ impl Drop for TestServer {
|
|||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.done.store(true, Ordering::SeqCst);
|
self.done.store(true, Ordering::SeqCst);
|
||||||
// Connect once to unblock the listen loop.
|
// Connect once to unblock the listen loop.
|
||||||
match TcpStream::connect(format!("localhost:{}", self.port)) {
|
if let Err(e) = TcpStream::connect(format!("localhost:{}", self.port)) {
|
||||||
Err(e) => eprintln!("error dropping testserver: {}", e),
|
eprintln!("error dropping testserver: {}", e);
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ impl Unit {
|
|||||||
agent: &Agent,
|
agent: &Agent,
|
||||||
method: &str,
|
method: &str,
|
||||||
url: &Url,
|
url: &Url,
|
||||||
headers: &Vec<Header>,
|
headers: &[Header],
|
||||||
body: &SizedReader,
|
body: &SizedReader,
|
||||||
deadline: Option<time::Instant>,
|
deadline: Option<time::Instant>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -229,7 +229,7 @@ fn connect_inner(
|
|||||||
let host = unit
|
let host = unit
|
||||||
.url
|
.url
|
||||||
.host_str()
|
.host_str()
|
||||||
.ok_or(ErrorKind::InvalidUrl.msg("no host in URL"))?;
|
.ok_or_else(|| ErrorKind::InvalidUrl.msg("no host in URL"))?;
|
||||||
let url = &unit.url;
|
let url = &unit.url;
|
||||||
let method = &unit.method;
|
let method = &unit.method;
|
||||||
// open socket
|
// open socket
|
||||||
|
|||||||
Reference in New Issue
Block a user