Skip to content

Commit 3503e93

Browse files
tottotoseanmonstar
authored andcommitted
refactor(proto): refactor conditional expression
1 parent 26f8675 commit 3503e93

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

src/proto/h1/conn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ where
649649
}
650650

651651
pub(crate) fn write_trailers(&mut self, trailers: HeaderMap) {
652-
if T::is_server() && self.state.allow_trailer_fields == false {
652+
if T::is_server() && !self.state.allow_trailer_fields {
653653
debug!("trailers not allowed to be sent");
654654
return;
655655
}

src/proto/h1/encode.rs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ impl Encoder {
110110
}
111111

112112
pub(crate) fn is_chunked(&self) -> bool {
113-
match self.kind {
114-
Kind::Chunked(_) => true,
115-
_ => false,
116-
}
113+
matches!(self.kind, Kind::Chunked(_))
117114
}
118115

119116
pub(crate) fn end<B>(&self) -> Result<Option<EncodedBuf<B>>, NotEof> {
@@ -182,7 +179,7 @@ impl Encoder {
182179
let name = cur_name.as_ref().expect("current header name");
183180

184181
if allowed_trailer_field_map.contains_key(name.as_str())
185-
&& valid_trailer_field(name)
182+
&& is_valid_trailer_field(name)
186183
{
187184
allowed_trailers.insert(name, value);
188185
}
@@ -255,22 +252,22 @@ impl Encoder {
255252
}
256253
}
257254

258-
fn valid_trailer_field(name: &HeaderName) -> bool {
259-
match name {
260-
&AUTHORIZATION => false,
261-
&CACHE_CONTROL => false,
262-
&CONTENT_ENCODING => false,
263-
&CONTENT_LENGTH => false,
264-
&CONTENT_RANGE => false,
265-
&CONTENT_TYPE => false,
266-
&HOST => false,
267-
&MAX_FORWARDS => false,
268-
&SET_COOKIE => false,
269-
&TRAILER => false,
270-
&TRANSFER_ENCODING => false,
271-
&TE => false,
272-
_ => true,
273-
}
255+
fn is_valid_trailer_field(name: &HeaderName) -> bool {
256+
!matches!(
257+
*name,
258+
AUTHORIZATION
259+
| CACHE_CONTROL
260+
| CONTENT_ENCODING
261+
| CONTENT_LENGTH
262+
| CONTENT_RANGE
263+
| CONTENT_TYPE
264+
| HOST
265+
| MAX_FORWARDS
266+
| SET_COOKIE
267+
| TRAILER
268+
| TRANSFER_ENCODING
269+
| TE
270+
)
274271
}
275272

276273
fn allowed_trailer_field_map(allowed_trailer_fields: &Vec<HeaderValue>) -> HashMap<String, ()> {

0 commit comments

Comments
 (0)