src, ci: enable clippy

as in other http-rs repos
This commit is contained in:
Jeremiah Senkpiel 2020-09-14 16:16:29 -07:00 committed by Jacob Rothstein
parent 1641e2263f
commit cfd9398242
8 changed files with 22 additions and 24 deletions

View File

@ -47,7 +47,7 @@ jobs:
args: --all
check_fmt_and_docs:
name: Checking fmt and docs
name: Checking fmt, clippy, and docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
@ -57,6 +57,9 @@ jobs:
components: rustfmt, clippy
override: true
- name: clippy
run: cargo clippy --tests --examples -- -D warnings
- name: fmt
run: cargo fmt --all -- --check

View File

@ -209,11 +209,7 @@ impl<R: Read + Unpin> Read for ChunkedDecoder<R> {
let mut n = std::mem::replace(&mut this.current, 0..0);
let buffer = std::mem::replace(&mut this.buffer, POOL.alloc(INITIAL_CAPACITY));
let mut needs_read = if let State::Chunk(_, _) = this.state {
false // Do not attempt to fill the buffer when we are reading a chunk
} else {
true
};
let mut needs_read = !matches!(this.state, State::Chunk(_, _));
let mut buffer = if n.len() > 0 && this.initial_decode {
// initial buffer filling, if needed
@ -541,13 +537,13 @@ mod tests {
#[test]
fn test_chunked_big() {
async_std::task::block_on(async move {
let mut input: Vec<u8> = "800\r\n".as_bytes().to_vec();
let mut input: Vec<u8> = b"800\r\n".to_vec();
input.extend(vec![b'X'; 2048]);
input.extend("\r\n1800\r\n".as_bytes());
input.extend(b"\r\n1800\r\n");
input.extend(vec![b'Y'; 6144]);
input.extend("\r\n800\r\n".as_bytes());
input.extend(b"\r\n800\r\n");
input.extend(vec![b'Z'; 2048]);
input.extend("\r\n0\r\n\r\n".as_bytes());
input.extend(b"\r\n0\r\n\r\n");
let (s, _r) = async_std::sync::channel(1);
let sender = Sender::new(s);

View File

@ -148,13 +148,13 @@ impl ChunkedEncoder {
// Each chunk is prefixed with the length of the data in hex, then a
// CRLF, then the content, then another CRLF. Calculate how many bytes
// each part should be.
let buf_len = buf.len().checked_sub(self.bytes_written).unwrap_or(0);
let buf_len = buf.len().saturating_sub(self.bytes_written);
let msg_len = src.len().min(buf_len);
// Calculate the max char count encoding the `len_prefix` statement
// as hex would take. This is done by rounding up `log16(amt + 1)`.
let hex_len = ((msg_len + 1) as f64).log(16.0).ceil() as usize;
let framing_len = hex_len + CRLF_LEN * 2;
let buf_upper = buf_len.checked_sub(framing_len).unwrap_or(0);
let buf_upper = buf_len.saturating_sub(framing_len);
let msg_len = msg_len.min(buf_upper);
let len_prefix = format!("{:X}", msg_len).into_bytes();

View File

@ -39,10 +39,10 @@ where
// We've hit the end delimiter of the stream.
let idx = buf.len() - 1;
if idx >= 3 && &buf[idx - 3..=idx] == [CR, LF, CR, LF] {
if idx >= 3 && buf[idx - 3..=idx] == [CR, LF, CR, LF] {
break;
}
if idx >= 1 && &buf[idx - 1..=idx] == [LF, LF] {
if idx >= 1 && buf[idx - 1..=idx] == [LF, LF] {
break;
}
}

View File

@ -15,7 +15,7 @@ const SECONDS_IN_HOUR: u64 = 3600;
/// Format using the `Display` trait.
/// Convert timestamp into/from `SytemTime` to use.
/// Supports comparison and sorting.
#[derive(Copy, Clone, Debug, Eq, Ord)]
#[derive(Copy, Clone, Debug, Eq)]
pub struct HttpDate {
/// 0...59
second: u8,

View File

@ -135,8 +135,7 @@ fn url_from_httparse_req(req: &httparse::Request<'_, '_>) -> http_types::Result<
let host = req
.headers
.iter()
.filter(|x| x.name.eq_ignore_ascii_case("host"))
.next()
.find(|x| x.name.eq_ignore_ascii_case("host"))
.ok_or_else(|| format_err!("Mandatory Host header missing"))?
.value;
@ -144,7 +143,7 @@ fn url_from_httparse_req(req: &httparse::Request<'_, '_>) -> http_types::Result<
if path.starts_with("http://") || path.starts_with("https://") {
Ok(Url::parse(path)?)
} else if path.starts_with("/") {
} else if path.starts_with('/') {
Ok(Url::parse(&format!("http://{}/", host))?.join(path)?)
} else if req.method.unwrap().eq_ignore_ascii_case("connect") {
Ok(Url::parse(&format!("http://{}/", path))?)

View File

@ -4,7 +4,7 @@ use http_types::{Body, Response, StatusCode};
mod common;
const REQUEST: &'static str = concat![
const REQUEST: &str = concat![
"GET / HTTP/1.1\r\n",
"host: example.com\r\n",
"user-agent: curl/7.54.0\r\n",
@ -12,7 +12,7 @@ const REQUEST: &'static str = concat![
"\r\n",
];
const TEXT: &'static str = concat![
const TEXT: &str = concat![
"Et provident reprehenderit accusamus dolores et voluptates sed quia. Repellendus odit porro ut et hic molestiae. Sit autem reiciendis animi fugiat deleniti vel iste. Laborum id odio ullam ut impedit dolores. Vel aperiam dolorem voluptatibus dignissimos maxime.",
"Qui cumque autem debitis consequatur aliquam impedit id nostrum. Placeat error temporibus quos sed vel rerum. Fugit perferendis enim voluptatem rerum vitae dolor distinctio. Quia iusto ex enim voluptatum omnis. Nam et aperiam asperiores nesciunt eos magnam quidem et.",
"Beatae et sit iure eum voluptatem accusantium quia optio. Tempora et rerum blanditiis repellendus qui est dolorem. Blanditiis deserunt qui dignissimos ad eligendi. Qui quia sequi et. Ipsa error quia quo ducimus et. Asperiores accusantium eius possimus dolore vitae iusto.",
@ -71,7 +71,7 @@ const TEXT: &'static str = concat![
"Nemo nemo iste qui voluptas itaque. Quae quis qui qui cum quod natus itaque est. Dolores voluptate sapiente ipsa eveniet doloremque laboriosam velit sunt. Optio voluptatum doloremque tenetur voluptate.",
];
const RESPONSE: &'static str = concat![
const RESPONSE: &str = concat![
"HTTP/1.1 200 OK\r\n",
"transfer-encoding: chunked\r\n",
"date: {DATE}\r\n",

View File

@ -4,7 +4,7 @@ use http_types::{Body, Response, StatusCode};
mod common;
const REQUEST: &'static str = concat![
const REQUEST: &str = concat![
"GET / HTTP/1.1\r\n",
"host: example.com\r\n",
"user-agent: curl/7.54.0\r\n",
@ -12,7 +12,7 @@ const REQUEST: &'static str = concat![
"\r\n",
];
const TEXT: &'static str = concat![
const TEXT: &str = concat![
"Eveniet delectus voluptatem in placeat modi. Qui nulla sunt aut non voluptas temporibus accusamus rem. Qui soluta nisi qui accusantium excepturi voluptatem. Ab rerum maiores neque ut expedita rem.",
"Et neque praesentium eligendi quaerat consequatur asperiores dolorem. Pariatur tempore quidem animi consequuntur voluptatem quos. Porro quo ipsa quae suscipit. Doloribus est qui facilis ratione. Delectus ex perspiciatis ab alias et quisquam non est.",
"Id dolorum distinctio distinctio quos est facilis commodi velit. Ex repudiandae aliquam eos voluptatum et. Provident qui molestiae molestiae nostrum voluptatum aperiam ut. Quis repellendus quidem mollitia aut recusandae laboriosam.",
@ -20,7 +20,7 @@ const TEXT: &'static str = concat![
"Eos maxime hic aliquid accusantium. Et voluptas sit accusamus modi natus. Et voluptatem sequi ea et provident voluptatum minus voluptas. Culpa aliquam architecto consequatur animi.",
];
const RESPONSE: &'static str = concat![
const RESPONSE: &str = concat![
"HTTP/1.1 200 OK\r\n",
"transfer-encoding: chunked\r\n",
"date: {DATE}\r\n",