cargo fmt
This commit is contained in:
11
src/body.rs
11
src/body.rs
@@ -1,5 +1,5 @@
|
|||||||
use crate::stream::Stream;
|
use crate::stream::Stream;
|
||||||
use std::io::{copy, empty, Cursor, Read, Write, Result as IoResult};
|
use std::io::{copy, empty, Cursor, Read, Result as IoResult, Write};
|
||||||
|
|
||||||
#[cfg(feature = "charset")]
|
#[cfg(feature = "charset")]
|
||||||
use crate::response::DEFAULT_CHARACTER_SET;
|
use crate::response::DEFAULT_CHARACTER_SET;
|
||||||
@@ -97,12 +97,11 @@ impl Payload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const CHUNK_MAX_SIZE: usize = 0x4000; // Maximum size of a TLS fragment
|
const CHUNK_MAX_SIZE: usize = 0x4000; // Maximum size of a TLS fragment
|
||||||
const CHUNK_HEADER_MAX_SIZE: usize = 6; // four hex digits plus "\r\n"
|
const CHUNK_HEADER_MAX_SIZE: usize = 6; // four hex digits plus "\r\n"
|
||||||
const CHUNK_FOOTER_SIZE: usize = 2; // "\r\n"
|
const CHUNK_FOOTER_SIZE: usize = 2; // "\r\n"
|
||||||
const CHUNK_MAX_PAYLOAD_SIZE: usize = CHUNK_MAX_SIZE - CHUNK_HEADER_MAX_SIZE - CHUNK_FOOTER_SIZE;
|
const CHUNK_MAX_PAYLOAD_SIZE: usize = CHUNK_MAX_SIZE - CHUNK_HEADER_MAX_SIZE - CHUNK_FOOTER_SIZE;
|
||||||
|
|
||||||
|
|
||||||
// copy_chunks() improves over chunked_transfer's Encoder + io::copy with the
|
// copy_chunks() improves over chunked_transfer's Encoder + io::copy with the
|
||||||
// following performance optimizations:
|
// following performance optimizations:
|
||||||
// 1) It avoid copying memory.
|
// 1) It avoid copying memory.
|
||||||
@@ -117,7 +116,9 @@ fn copy_chunked<R: Read, W: Write>(reader: &mut R, writer: &mut W) -> IoResult<u
|
|||||||
loop {
|
loop {
|
||||||
// We first read the payload
|
// We first read the payload
|
||||||
chunk.resize(CHUNK_HEADER_MAX_SIZE, 0);
|
chunk.resize(CHUNK_HEADER_MAX_SIZE, 0);
|
||||||
let payload_size = reader.take(CHUNK_MAX_PAYLOAD_SIZE as u64).read_to_end(&mut chunk)?;
|
let payload_size = reader
|
||||||
|
.take(CHUNK_MAX_PAYLOAD_SIZE as u64)
|
||||||
|
.read_to_end(&mut chunk)?;
|
||||||
|
|
||||||
// Then write the header
|
// Then write the header
|
||||||
let header_str = format!("{:x}\r\n", payload_size);
|
let header_str = format!("{:x}\r\n", payload_size);
|
||||||
|
|||||||
@@ -136,13 +136,15 @@ pub(crate) fn connect_http(unit: &Unit) -> Result<Stream, Error> {
|
|||||||
|
|
||||||
#[cfg(all(feature = "tls", feature = "native-certs"))]
|
#[cfg(all(feature = "tls", feature = "native-certs"))]
|
||||||
fn configure_certs(config: &mut rustls::ClientConfig) {
|
fn configure_certs(config: &mut rustls::ClientConfig) {
|
||||||
config.root_store = rustls_native_certs::load_native_certs()
|
config.root_store =
|
||||||
.expect("Could not load patform certs");
|
rustls_native_certs::load_native_certs().expect("Could not load patform certs");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "tls", not(feature = "native-certs")))]
|
#[cfg(all(feature = "tls", not(feature = "native-certs")))]
|
||||||
fn configure_certs(config: &mut rustls::ClientConfig) {
|
fn configure_certs(config: &mut rustls::ClientConfig) {
|
||||||
config.root_store.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
|
config
|
||||||
|
.root_store
|
||||||
|
.add_server_trust_anchors(&webpki_roots::TLS_SERVER_ROOTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
@@ -316,9 +318,9 @@ fn connect_socks5(
|
|||||||
// TODO: explore supporting timeouts upstream in Socks5Proxy.
|
// TODO: explore supporting timeouts upstream in Socks5Proxy.
|
||||||
#[allow(clippy::mutex_atomic)]
|
#[allow(clippy::mutex_atomic)]
|
||||||
let stream = if timeout_connect > 0 {
|
let stream = if timeout_connect > 0 {
|
||||||
|
use std::sync::mpsc::channel;
|
||||||
use std::sync::{Arc, Condvar, Mutex};
|
use std::sync::{Arc, Condvar, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::sync::mpsc::channel;
|
|
||||||
let master_signal = Arc::new((Mutex::new(false), Condvar::new()));
|
let master_signal = Arc::new((Mutex::new(false), Condvar::new()));
|
||||||
let slave_signal = master_signal.clone();
|
let slave_signal = master_signal.clone();
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|||||||
Reference in New Issue
Block a user