1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 00:21:08 +01:00

fix warns

This commit is contained in:
Nikolay Kim 2019-02-07 19:53:48 -08:00
parent 2a6e4dc7ab
commit a7a2d4cf5c
6 changed files with 40 additions and 41 deletions

View File

@ -18,7 +18,7 @@ fn main() {
.client_timeout(1000)
.client_disconnect(1000)
.server_hostname("localhost")
.finish(|mut req: Request| {
.finish(|req: Request| {
req.body().limit(512).and_then(|bytes: Bytes| {
info!("request body: {:?}", bytes);
let mut res = Response::Ok();

View File

@ -8,7 +8,7 @@ use futures::Future;
use log::info;
use std::env;
fn handle_request(mut req: Request) -> impl Future<Item = Response, Error = Error> {
fn handle_request(req: Request) -> impl Future<Item = Response, Error = Error> {
req.body().limit(512).from_err().and_then(|bytes: Bytes| {
info!("request body: {:?}", bytes);
let mut res = Response::Ok();

View File

@ -128,7 +128,7 @@ pub trait HttpMessage: Sized {
/// }
/// # fn main() {}
/// ```
fn body(&mut self) -> MessageBody<Self> {
fn body(&self) -> MessageBody<Self> {
MessageBody::new(self)
}
@ -162,7 +162,7 @@ pub trait HttpMessage: Sized {
/// }
/// # fn main() {}
/// ```
fn urlencoded<T: DeserializeOwned>(&mut self) -> UrlEncoded<Self, T> {
fn urlencoded<T: DeserializeOwned>(&self) -> UrlEncoded<Self, T> {
UrlEncoded::new(self)
}
@ -198,12 +198,12 @@ pub trait HttpMessage: Sized {
/// }
/// # fn main() {}
/// ```
fn json<T: DeserializeOwned>(&mut self) -> JsonBody<Self, T> {
fn json<T: DeserializeOwned>(&self) -> JsonBody<Self, T> {
JsonBody::new(self)
}
/// Return stream of lines.
fn readlines(&mut self) -> Readlines<Self> {
fn readlines(&self) -> Readlines<Self> {
Readlines::new(self)
}
}
@ -220,10 +220,10 @@ pub struct Readlines<T: HttpMessage> {
impl<T: HttpMessage> Readlines<T> {
/// Create a new stream to read request line by line.
fn new(req: &mut T) -> Self {
fn new(req: &T) -> Self {
let encoding = match req.encoding() {
Ok(enc) => enc,
Err(err) => return Self::err(req, err.into()),
Err(err) => return Self::err(err.into()),
};
Readlines {
@ -242,9 +242,9 @@ impl<T: HttpMessage> Readlines<T> {
self
}
fn err(req: &mut T, err: ReadlinesError) -> Self {
fn err(err: ReadlinesError) -> Self {
Readlines {
stream: req.payload(),
stream: None,
buff: BytesMut::new(),
limit: 262_144,
checked_buff: true,
@ -366,7 +366,7 @@ pub struct MessageBody<T: HttpMessage> {
impl<T: HttpMessage> MessageBody<T> {
/// Create `MessageBody` for request.
pub fn new(req: &mut T) -> MessageBody<T> {
pub fn new(req: &T) -> MessageBody<T> {
let mut len = None;
if let Some(l) = req.headers().get(header::CONTENT_LENGTH) {
if let Ok(s) = l.to_str() {
@ -465,7 +465,7 @@ pub struct UrlEncoded<T: HttpMessage, U> {
impl<T: HttpMessage, U> UrlEncoded<T, U> {
/// Create a new future to URL encode a request
pub fn new(req: &mut T) -> UrlEncoded<T, U> {
pub fn new(req: &T) -> UrlEncoded<T, U> {
// check content type
if req.content_type().to_lowercase() != "application/x-www-form-urlencoded" {
return Self::err(UrlencodedError::ContentType);
@ -702,7 +702,7 @@ mod tests {
#[test]
fn test_urlencoded_error() {
let mut req = TestRequest::with_header(
let req = TestRequest::with_header(
header::CONTENT_TYPE,
"application/x-www-form-urlencoded",
)
@ -713,7 +713,7 @@ mod tests {
UrlencodedError::UnknownLength
);
let mut req = TestRequest::with_header(
let req = TestRequest::with_header(
header::CONTENT_TYPE,
"application/x-www-form-urlencoded",
)
@ -724,7 +724,7 @@ mod tests {
UrlencodedError::Overflow
);
let mut req = TestRequest::with_header(header::CONTENT_TYPE, "text/plain")
let req = TestRequest::with_header(header::CONTENT_TYPE, "text/plain")
.header(header::CONTENT_LENGTH, "10")
.finish();
assert_eq!(
@ -735,7 +735,7 @@ mod tests {
#[test]
fn test_urlencoded() {
let mut req = TestRequest::with_header(
let req = TestRequest::with_header(
header::CONTENT_TYPE,
"application/x-www-form-urlencoded",
)
@ -751,7 +751,7 @@ mod tests {
})
);
let mut req = TestRequest::with_header(
let req = TestRequest::with_header(
header::CONTENT_TYPE,
"application/x-www-form-urlencoded; charset=utf-8",
)
@ -770,20 +770,19 @@ mod tests {
#[test]
fn test_message_body() {
let mut req = TestRequest::with_header(header::CONTENT_LENGTH, "xxxx").finish();
let req = TestRequest::with_header(header::CONTENT_LENGTH, "xxxx").finish();
match req.body().poll().err().unwrap() {
PayloadError::UnknownLength => (),
_ => unreachable!("error"),
}
let mut req =
TestRequest::with_header(header::CONTENT_LENGTH, "1000000").finish();
let req = TestRequest::with_header(header::CONTENT_LENGTH, "1000000").finish();
match req.body().poll().err().unwrap() {
PayloadError::Overflow => (),
_ => unreachable!("error"),
}
let mut req = TestRequest::default()
let req = TestRequest::default()
.set_payload(Bytes::from_static(b"test"))
.finish();
match req.body().poll().ok().unwrap() {
@ -791,7 +790,7 @@ mod tests {
_ => unreachable!("error"),
}
let mut req = TestRequest::default()
let req = TestRequest::default()
.set_payload(Bytes::from_static(b"11111111111111"))
.finish();
match req.body().limit(5).poll().err().unwrap() {
@ -802,14 +801,14 @@ mod tests {
#[test]
fn test_readlines() {
let mut req = TestRequest::default()
let req = TestRequest::default()
.set_payload(Bytes::from_static(
b"Lorem Ipsum is simply dummy text of the printing and typesetting\n\
industry. Lorem Ipsum has been the industry's standard dummy\n\
Contrary to popular belief, Lorem Ipsum is not simply random text.",
))
.finish();
let mut r = Readlines::new(&mut req);
let mut r = Readlines::new(&req);
match r.poll().ok().unwrap() {
Async::Ready(Some(s)) => assert_eq!(
s,

View File

@ -50,7 +50,7 @@ pub struct JsonBody<T: HttpMessage, U: DeserializeOwned> {
impl<T: HttpMessage, U: DeserializeOwned> JsonBody<T, U> {
/// Create `JsonBody` for request.
pub fn new(req: &mut T) -> Self {
pub fn new(req: &T) -> Self {
// check content-type
let json = if let Ok(Some(mime)) = req.mime_type() {
mime.subtype() == mime::JSON || mime.suffix() == Some(mime::JSON)
@ -164,11 +164,11 @@ mod tests {
#[test]
fn test_json_body() {
let mut req = TestRequest::default().finish();
let req = TestRequest::default().finish();
let mut json = req.json::<MyObject>();
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::ContentType);
let mut req = TestRequest::default()
let req = TestRequest::default()
.header(
header::CONTENT_TYPE,
header::HeaderValue::from_static("application/text"),
@ -177,7 +177,7 @@ mod tests {
let mut json = req.json::<MyObject>();
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::ContentType);
let mut req = TestRequest::default()
let req = TestRequest::default()
.header(
header::CONTENT_TYPE,
header::HeaderValue::from_static("application/json"),
@ -190,7 +190,7 @@ mod tests {
let mut json = req.json::<MyObject>().limit(100);
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::Overflow);
let mut req = TestRequest::default()
let req = TestRequest::default()
.header(
header::CONTENT_TYPE,
header::HeaderValue::from_static("application/json"),

View File

@ -47,7 +47,7 @@ fn test_h1_v2() {
assert!(repr.contains("ClientRequest"));
assert!(repr.contains("x-test"));
let mut response = srv.block_on(request.send(&mut connector)).unwrap();
let response = srv.block_on(request.send(&mut connector)).unwrap();
assert!(response.status().is_success());
// read response
@ -55,7 +55,7 @@ fn test_h1_v2() {
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
let request = srv.post().finish().unwrap();
let mut response = srv.block_on(request.send(&mut connector)).unwrap();
let response = srv.block_on(request.send(&mut connector)).unwrap();
assert!(response.status().is_success());
// read response

View File

@ -89,7 +89,7 @@ fn test_h2_body() -> std::io::Result<()> {
.map_err(|e| println!("Openssl error: {}", e))
.and_then(
h2::H2Service::build()
.finish(|mut req: Request<_>| {
.finish(|req: Request<_>| {
req.body()
.limit(1024 * 1024)
.and_then(|body| Ok(Response::Ok().body(body)))
@ -101,7 +101,7 @@ fn test_h2_body() -> std::io::Result<()> {
let req = client::ClientRequest::get(srv.surl("/"))
.body(data.clone())
.unwrap();
let mut response = srv.send_request(req).unwrap();
let response = srv.send_request(req).unwrap();
assert!(response.status().is_success());
let body = srv.block_on(response.body().limit(1024 * 1024)).unwrap();
@ -350,7 +350,7 @@ fn test_headers() {
let req = srv.get().finish().unwrap();
let mut response = srv.block_on(req.send(&mut connector)).unwrap();
let response = srv.block_on(req.send(&mut connector)).unwrap();
assert!(response.status().is_success());
// read response
@ -387,7 +387,7 @@ fn test_body() {
});
let req = srv.get().finish().unwrap();
let mut response = srv.send_request(req).unwrap();
let response = srv.send_request(req).unwrap();
assert!(response.status().is_success());
// read response
@ -402,7 +402,7 @@ fn test_head_empty() {
});
let req = client::ClientRequest::head(srv.url("/")).finish().unwrap();
let mut response = srv.send_request(req).unwrap();
let response = srv.send_request(req).unwrap();
assert!(response.status().is_success());
{
@ -428,7 +428,7 @@ fn test_head_binary() {
});
let req = client::ClientRequest::head(srv.url("/")).finish().unwrap();
let mut response = srv.send_request(req).unwrap();
let response = srv.send_request(req).unwrap();
assert!(response.status().is_success());
{
@ -477,7 +477,7 @@ fn test_body_length() {
});
let req = srv.get().finish().unwrap();
let mut response = srv.send_request(req).unwrap();
let response = srv.send_request(req).unwrap();
assert!(response.status().is_success());
// read response
@ -496,7 +496,7 @@ fn test_body_chunked_explicit() {
});
let req = srv.get().finish().unwrap();
let mut response = srv.send_request(req).unwrap();
let response = srv.send_request(req).unwrap();
assert!(response.status().is_success());
// read response
@ -517,7 +517,7 @@ fn test_body_chunked_implicit() {
});
let req = srv.get().finish().unwrap();
let mut response = srv.send_request(req).unwrap();
let response = srv.send_request(req).unwrap();
assert!(response.status().is_success());
// read response
@ -540,7 +540,7 @@ fn test_response_http_error_handling() {
});
let req = srv.get().finish().unwrap();
let mut response = srv.send_request(req).unwrap();
let response = srv.send_request(req).unwrap();
assert_eq!(response.status(), http::StatusCode::INTERNAL_SERVER_ERROR);
// read response