Skip to content

Commit cfd9398

Browse files
Fishrock123jbr
authored andcommitted
src, ci: enable clippy
as in other http-rs repos
1 parent 1641e22 commit cfd9398

File tree

8 files changed

+22
-24
lines changed

8 files changed

+22
-24
lines changed

.github/workflows/ci.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
args: --all
4848

4949
check_fmt_and_docs:
50-
name: Checking fmt and docs
50+
name: Checking fmt, clippy, and docs
5151
runs-on: ubuntu-latest
5252
steps:
5353
- uses: actions/checkout@master
@@ -57,6 +57,9 @@ jobs:
5757
components: rustfmt, clippy
5858
override: true
5959

60+
- name: clippy
61+
run: cargo clippy --tests --examples -- -D warnings
62+
6063
- name: fmt
6164
run: cargo fmt --all -- --check
6265

src/chunked/decoder.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,7 @@ impl<R: Read + Unpin> Read for ChunkedDecoder<R> {
209209

210210
let mut n = std::mem::replace(&mut this.current, 0..0);
211211
let buffer = std::mem::replace(&mut this.buffer, POOL.alloc(INITIAL_CAPACITY));
212-
let mut needs_read = if let State::Chunk(_, _) = this.state {
213-
false // Do not attempt to fill the buffer when we are reading a chunk
214-
} else {
215-
true
216-
};
212+
let mut needs_read = !matches!(this.state, State::Chunk(_, _));
217213

218214
let mut buffer = if n.len() > 0 && this.initial_decode {
219215
// initial buffer filling, if needed
@@ -541,13 +537,13 @@ mod tests {
541537
#[test]
542538
fn test_chunked_big() {
543539
async_std::task::block_on(async move {
544-
let mut input: Vec<u8> = "800\r\n".as_bytes().to_vec();
540+
let mut input: Vec<u8> = b"800\r\n".to_vec();
545541
input.extend(vec![b'X'; 2048]);
546-
input.extend("\r\n1800\r\n".as_bytes());
542+
input.extend(b"\r\n1800\r\n");
547543
input.extend(vec![b'Y'; 6144]);
548-
input.extend("\r\n800\r\n".as_bytes());
544+
input.extend(b"\r\n800\r\n");
549545
input.extend(vec![b'Z'; 2048]);
550-
input.extend("\r\n0\r\n\r\n".as_bytes());
546+
input.extend(b"\r\n0\r\n\r\n");
551547

552548
let (s, _r) = async_std::sync::channel(1);
553549
let sender = Sender::new(s);

src/chunked/encoder.rs

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

src/client/decode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ where
3939

4040
// We've hit the end delimiter of the stream.
4141
let idx = buf.len() - 1;
42-
if idx >= 3 && &buf[idx - 3..=idx] == [CR, LF, CR, LF] {
42+
if idx >= 3 && buf[idx - 3..=idx] == [CR, LF, CR, LF] {
4343
break;
4444
}
45-
if idx >= 1 && &buf[idx - 1..=idx] == [LF, LF] {
45+
if idx >= 1 && buf[idx - 1..=idx] == [LF, LF] {
4646
break;
4747
}
4848
}

src/date.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const SECONDS_IN_HOUR: u64 = 3600;
1515
/// Format using the `Display` trait.
1616
/// Convert timestamp into/from `SytemTime` to use.
1717
/// Supports comparison and sorting.
18-
#[derive(Copy, Clone, Debug, Eq, Ord)]
18+
#[derive(Copy, Clone, Debug, Eq)]
1919
pub struct HttpDate {
2020
/// 0...59
2121
second: u8,

src/server/decode.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,15 @@ fn url_from_httparse_req(req: &httparse::Request<'_, '_>) -> http_types::Result<
135135
let host = req
136136
.headers
137137
.iter()
138-
.filter(|x| x.name.eq_ignore_ascii_case("host"))
139-
.next()
138+
.find(|x| x.name.eq_ignore_ascii_case("host"))
140139
.ok_or_else(|| format_err!("Mandatory Host header missing"))?
141140
.value;
142141

143142
let host = std::str::from_utf8(host)?;
144143

145144
if path.starts_with("http://") || path.starts_with("https://") {
146145
Ok(Url::parse(path)?)
147-
} else if path.starts_with("/") {
146+
} else if path.starts_with('/') {
148147
Ok(Url::parse(&format!("http://{}/", host))?.join(path)?)
149148
} else if req.method.unwrap().eq_ignore_ascii_case("connect") {
150149
Ok(Url::parse(&format!("http://{}/", path))?)

tests/server-chunked-encode-large.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ use http_types::{Body, Response, StatusCode};
44

55
mod common;
66

7-
const REQUEST: &'static str = concat![
7+
const REQUEST: &str = concat![
88
"GET / HTTP/1.1\r\n",
99
"host: example.com\r\n",
1010
"user-agent: curl/7.54.0\r\n",
1111
"content-type: text/plain\r\n",
1212
"\r\n",
1313
];
1414

15-
const TEXT: &'static str = concat![
15+
const TEXT: &str = concat![
1616
"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.",
1717
"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.",
1818
"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![
7171
"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.",
7272
];
7373

74-
const RESPONSE: &'static str = concat![
74+
const RESPONSE: &str = concat![
7575
"HTTP/1.1 200 OK\r\n",
7676
"transfer-encoding: chunked\r\n",
7777
"date: {DATE}\r\n",

tests/server-chunked-encode-small.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ use http_types::{Body, Response, StatusCode};
44

55
mod common;
66

7-
const REQUEST: &'static str = concat![
7+
const REQUEST: &str = concat![
88
"GET / HTTP/1.1\r\n",
99
"host: example.com\r\n",
1010
"user-agent: curl/7.54.0\r\n",
1111
"content-type: text/plain\r\n",
1212
"\r\n",
1313
];
1414

15-
const TEXT: &'static str = concat![
15+
const TEXT: &str = concat![
1616
"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.",
1717
"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.",
1818
"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.",
1919
"Corrupti cupiditate maxime voluptatibus totam neque facilis. Iure deleniti id incidunt in sunt suscipit ea. Hic ullam qui doloribus tempora voluptas. Unde id debitis architecto beatae dolores autem et omnis. Impedit accusamus laudantium voluptatem ducimus.",
2020
"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.",
2121
];
2222

23-
const RESPONSE: &'static str = concat![
23+
const RESPONSE: &str = concat![
2424
"HTTP/1.1 200 OK\r\n",
2525
"transfer-encoding: chunked\r\n",
2626
"date: {DATE}\r\n",

0 commit comments

Comments
 (0)