Skip to content

Commit 02e0bc0

Browse files
committed
style(proto): fmt code
1 parent f025e3f commit 02e0bc0

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

src/core/client/body/length.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::fmt;
22

3+
use crate::core::error::Parse;
4+
35
#[derive(Clone, Copy, PartialEq, Eq)]
46
pub(crate) struct DecodedLength(u64);
57

@@ -45,12 +47,12 @@ impl DecodedLength {
4547
}
4648

4749
/// Checks the `u64` is within the maximum allowed for content-length.
48-
pub(crate) fn checked_new(len: u64) -> Result<Self, crate::core::error::Parse> {
50+
pub(crate) fn checked_new(len: u64) -> Result<Self, Parse> {
4951
if len <= MAX_LEN {
5052
Ok(DecodedLength(len))
5153
} else {
5254
warn!("content-length bigger than maximum: {} > {}", len, MAX_LEN);
53-
Err(crate::core::error::Parse::TooLarge)
55+
Err(Parse::TooLarge)
5456
}
5557
}
5658

src/core/client/proto/h1/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
mod conn;
2+
mod decode;
3+
pub(crate) mod dispatch;
4+
mod encode;
5+
mod io;
6+
mod role;
7+
18
use bytes::BytesMut;
29
use http::{HeaderMap, Method};
310
use httparse::ParserConfig;
411

5-
//TODO: move out of h1::io
6-
pub(crate) use self::io::MINIMUM_MAX_BUFFER_SIZE;
712
pub(crate) use self::{
813
conn::Conn,
914
decode::Decoder,
1015
dispatch::Dispatcher,
1116
encode::{EncodedBuf, Encoder},
17+
io::MINIMUM_MAX_BUFFER_SIZE,
1218
};
1319
use crate::core::{
1420
client::{
@@ -18,21 +24,18 @@ use crate::core::{
1824
error::{Error, Parse, Result},
1925
};
2026

21-
mod conn;
22-
mod decode;
23-
pub(crate) mod dispatch;
24-
mod encode;
25-
mod io;
26-
mod role;
27-
2827
pub(crate) type ClientTransaction = role::Client;
2928

3029
pub(crate) trait Http1Transaction {
3130
type Incoming;
31+
3232
type Outgoing: Default;
33+
3334
#[cfg(feature = "tracing")]
3435
const LOG: &'static str;
36+
3537
fn parse(bytes: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult<Self::Incoming>;
38+
3639
fn encode(enc: Encode<'_, Self::Outgoing>, dst: &mut Vec<u8>) -> Result<Encoder>;
3740

3841
fn on_error(err: &Error) -> Option<MessageHead<Self::Outgoing>>;

src/core/client/proto/h1/role.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ use crate::{
2727
header::{OrigHeaderMap, OrigHeaderName},
2828
};
2929

30+
/// totally scientific
31+
const AVERAGE_HEADER_SIZE: usize = 30;
3032
pub(crate) const DEFAULT_MAX_HEADERS: usize = 100;
31-
const AVERAGE_HEADER_SIZE: usize = 30; // totally scientific
3233

3334
macro_rules! header_name {
3435
($bytes:expr) => {{
@@ -392,6 +393,7 @@ impl Client {
392393
trace!("neither Transfer-Encoding nor Content-Length");
393394
Ok(Some((DecodedLength::CLOSE_DELIMITED, false)))
394395
}
396+
395397
fn set_length(head: &mut RequestHead, body: Option<BodyLength>) -> Encoder {
396398
let body = if let Some(body) = body {
397399
body
@@ -619,13 +621,13 @@ fn record_header_indices(
619621
bytes: &[u8],
620622
headers: &[httparse::Header<'_>],
621623
indices: &mut [MaybeUninit<HeaderIndices>],
622-
) -> Result<(), crate::core::error::Parse> {
624+
) -> Result<(), Parse> {
623625
let bytes_ptr = bytes.as_ptr() as usize;
624626

625627
for (header, indices) in headers.iter().zip(indices.iter_mut()) {
626628
if header.name.len() >= (1 << 16) {
627629
debug!("header name larger than 64kb: {:?}", header.name);
628-
return Err(crate::core::error::Parse::TooLarge);
630+
return Err(Parse::TooLarge);
629631
}
630632
let name_start = header.name.as_ptr() as usize - bytes_ptr;
631633
let name_end = name_start + header.name.len();
@@ -643,7 +645,7 @@ fn record_header_indices(
643645

644646
pub(crate) fn write_headers(headers: &HeaderMap, dst: &mut Vec<u8>) {
645647
for (name, value) in headers {
646-
extend(dst, name.as_str().as_bytes());
648+
extend(dst, name.as_ref());
647649
extend(dst, b": ");
648650
extend(dst, value.as_bytes());
649651
extend(dst, b"\r\n");

0 commit comments

Comments
 (0)