mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-28 01:52:57 +01:00
cleanup more code
This commit is contained in:
parent
a69c1e3de5
commit
311f0b23a9
@ -10,7 +10,7 @@ use std::{cmp, io};
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
|
||||||
use bytes::{BufMut, Bytes, BytesMut};
|
use bytes::Bytes;
|
||||||
use futures::{Async, Future, Poll, Stream};
|
use futures::{Async, Future, Poll, Stream};
|
||||||
use futures_cpupool::{CpuFuture, CpuPool};
|
use futures_cpupool::{CpuFuture, CpuPool};
|
||||||
use mime;
|
use mime;
|
||||||
@ -439,14 +439,13 @@ impl Stream for ChunkedReadFile {
|
|||||||
self.fut = Some(self.cpu_pool.spawn_fn(move || {
|
self.fut = Some(self.cpu_pool.spawn_fn(move || {
|
||||||
let max_bytes: usize;
|
let max_bytes: usize;
|
||||||
max_bytes = cmp::min(size.saturating_sub(counter), 65_536) as usize;
|
max_bytes = cmp::min(size.saturating_sub(counter), 65_536) as usize;
|
||||||
let mut buf = BytesMut::from(Vec::with_capacity(max_bytes));
|
let mut buf = Vec::with_capacity(max_bytes);
|
||||||
file.seek(io::SeekFrom::Start(offset))?;
|
file.seek(io::SeekFrom::Start(offset))?;
|
||||||
let nbytes = file.read(unsafe { buf.bytes_mut() })?;
|
let nbytes = file.read(buf.as_mut_slice())?;
|
||||||
if nbytes == 0 {
|
if nbytes == 0 {
|
||||||
return Err(io::ErrorKind::UnexpectedEof.into());
|
return Err(io::ErrorKind::UnexpectedEof.into());
|
||||||
}
|
}
|
||||||
unsafe { buf.advance_mut(nbytes) };
|
Ok((file, Bytes::from(buf)))
|
||||||
Ok((file, buf.freeze()))
|
|
||||||
}));
|
}));
|
||||||
self.poll()
|
self.poll()
|
||||||
}
|
}
|
||||||
|
@ -634,13 +634,11 @@ mod tests {
|
|||||||
assert!(req.chunked().unwrap());
|
assert!(req.chunked().unwrap());
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
let mut headers = HeaderMap::new();
|
||||||
let s = unsafe {
|
let hdr = Bytes::from_static(b"some va\xadscc\xacas0xsdasdlue");
|
||||||
str::from_utf8_unchecked(b"some va\xadscc\xacas0xsdasdlue".as_ref())
|
|
||||||
};
|
|
||||||
|
|
||||||
headers.insert(
|
headers.insert(
|
||||||
header::TRANSFER_ENCODING,
|
header::TRANSFER_ENCODING,
|
||||||
header::HeaderValue::from_str(s).unwrap(),
|
header::HeaderValue::from_shared(hdr).unwrap(),
|
||||||
);
|
);
|
||||||
let req = HttpRequest::new(
|
let req = HttpRequest::new(
|
||||||
Method::GET,
|
Method::GET,
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
//! HTTP Request message related code.
|
//! HTTP Request message related code.
|
||||||
#![cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ptr))]
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::{cmp, fmt, io, mem, str};
|
use std::{cmp, fmt, io, str};
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use cookie::Cookie;
|
use cookie::Cookie;
|
||||||
@ -446,13 +445,13 @@ impl<S> HttpRequest<S> {
|
|||||||
/// access the matched value for that segment.
|
/// access the matched value for that segment.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn match_info(&self) -> &Params {
|
pub fn match_info(&self) -> &Params {
|
||||||
unsafe { mem::transmute(&self.as_ref().params) }
|
&self.as_ref().params
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get mutable reference to request's Params.
|
/// Get mutable reference to request's Params.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn match_info_mut(&mut self) -> &mut Params {
|
pub(crate) fn match_info_mut(&mut self) -> &mut Params {
|
||||||
unsafe { mem::transmute(&mut self.as_mut().params) }
|
&mut self.as_mut().params
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if a connection should be kept alive.
|
/// Checks if a connection should be kept alive.
|
||||||
|
@ -146,6 +146,8 @@ impl Quoter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(data) = cloned {
|
if let Some(data) = cloned {
|
||||||
|
// we get data from http::Uri, which does utf-8 checks already
|
||||||
|
// this code only decodes valid pct encoded values
|
||||||
Some(unsafe { Rc::new(String::from_utf8_unchecked(data)) })
|
Some(unsafe { Rc::new(String::from_utf8_unchecked(data)) })
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
Loading…
Reference in New Issue
Block a user