Skip to content

Commit

Permalink
cleanup warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Jul 4, 2018
1 parent 4c5a639 commit 6fd686e
Show file tree
Hide file tree
Showing 39 changed files with 114 additions and 224 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ flate2-c = ["flate2/miniz-sys"]
flate2-rust = ["flate2/rust_backend"]

[dependencies]
# actix = "0.6.1"
# actix = "0.7.0"
actix = { git="https://github.com/actix/actix.git" }

base64 = "0.9"
Expand Down
20 changes: 8 additions & 12 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ use http::{Method, StatusCode};
use httprequest::HttpRequest;
use httpresponse::HttpResponse;
use middleware::Middleware;
use param::Params;
use pipeline::{HandlerType, Pipeline, PipelineHandler};
use pred::Predicate;
use resource::ResourceHandler;
use router::{Resource, RouteInfo, Router};
use scope::Scope;
use server::{HttpHandler, HttpHandlerTask, IntoHttpHandler, Request, ServerSettings};
use server::{HttpHandler, HttpHandlerTask, IntoHttpHandler, Request};

/// Application
pub struct HttpApplication<S = ()> {
Expand Down Expand Up @@ -102,23 +101,20 @@ impl<S: 'static> HttpApplication<S> {
continue 'outer;
}
}
let info = self
.router
.route_info_params(params, self.inner.prefix as u16);
return (info, HandlerType::Handler(idx));
return (
self.router.route_info_params(params),
HandlerType::Handler(idx),
);
}
}
}
}
(
self.router.default_route_info(self.inner.prefix as u16),
HandlerType::Default,
)
(self.router.default_route_info(), HandlerType::Default)
}
}

#[cfg(test)]
pub(crate) fn run(&self, mut req: Request) -> AsyncResult<HttpResponse> {
pub(crate) fn run(&self, req: Request) -> AsyncResult<HttpResponse> {
let (info, tp) = self.get_handler(&req);
let req = HttpRequest::new(req, Rc::clone(&self.state), info);

Expand All @@ -129,7 +125,7 @@ impl<S: 'static> HttpApplication<S> {
impl<S: 'static> HttpHandler for HttpApplication<S> {
type Task = Pipeline<S, Inner<S>>;

fn handle(&self, mut msg: Request) -> Result<Pipeline<S, Inner<S>>, Request> {
fn handle(&self, msg: Request) -> Result<Pipeline<S, Inner<S>>, Request> {
let m = {
let path = msg.path();
path.starts_with(&self.prefix)
Expand Down
20 changes: 8 additions & 12 deletions src/client/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::{fmt, io, mem, time};

use actix::resolver::{Connect as ResolveConnect, Resolver, ResolverError};
use actix::{
fut, Actor, ActorContext, ActorFuture, ActorResponse, Addr, AsyncContext, Context,
ContextFutureSpawner, Handler, Message, Recipient, StreamHandler2, Supervised,
fut, Actor, ActorFuture, ActorResponse, Addr, AsyncContext, Context,
ContextFutureSpawner, Handler, Message, Recipient, StreamHandler, Supervised,
SystemService, WrapFuture,
};

Expand Down Expand Up @@ -220,7 +220,7 @@ impl Actor for ClientConnector {
self.resolver = Some(Resolver::from_registry())
}
self.collect_periodic(ctx);
ctx.add_stream2(self.acq_rx.take().unwrap());
ctx.add_stream(self.acq_rx.take().unwrap());
ctx.spawn(Maintenance);
}
}
Expand Down Expand Up @@ -769,20 +769,17 @@ impl Handler<Connect> for ClientConnector {
}
}

impl StreamHandler2<AcquiredConnOperation, ()> for ClientConnector {
fn handle(
&mut self, msg: Result<Option<AcquiredConnOperation>, ()>,
ctx: &mut Context<Self>,
) {
impl StreamHandler<AcquiredConnOperation, ()> for ClientConnector {
fn handle(&mut self, msg: AcquiredConnOperation, _: &mut Context<Self>) {
let now = Instant::now();

match msg {
Ok(Some(AcquiredConnOperation::Close(conn))) => {
AcquiredConnOperation::Close(conn) => {
self.release_key(&conn.key);
self.to_close.push(conn);
self.stats.closed += 1;
}
Ok(Some(AcquiredConnOperation::Release(conn))) => {
AcquiredConnOperation::Release(conn) => {
self.release_key(&conn.key);

// check connection lifetime and the return to available pool
Expand All @@ -793,10 +790,9 @@ impl StreamHandler2<AcquiredConnOperation, ()> for ClientConnector {
.push_back(Conn(Instant::now(), conn));
}
}
Ok(Some(AcquiredConnOperation::ReleaseKey(key))) => {
AcquiredConnOperation::ReleaseKey(key) => {
self.release_key(&key);
}
_ => ctx.stop(),
}

// check keep-alive
Expand Down
4 changes: 1 addition & 3 deletions src/client/response.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::cell::RefCell;
use std::{fmt, str};

use bytes::Bytes;
use cookie::Cookie;
use futures::{Async, Poll, Stream};
use http::header::{self, HeaderValue};
use http::{HeaderMap, StatusCode, Version};

use error::{CookieParseError, PayloadError};
use error::CookieParseError;
use httpmessage::HttpMessage;

use super::pipeline::Pipeline;
Expand Down
2 changes: 1 addition & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ where
{
#[inline]
/// Create a new HTTP Context from a request and an actor
pub fn new(req: HttpRequest<S>, actor: A) -> Body {
pub fn create(req: HttpRequest<S>, actor: A) -> Body {
let mb = Mailbox::default();
let ctx = HttpContext {
inner: ContextParts::new(mb.sender_producer()),
Expand Down
2 changes: 1 addition & 1 deletion src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ mod tests {
routes.push((Resource::new("index", "/{key}/{value}/"), Some(resource)));
let (router, _) = Router::new("", routes);

let mut req = TestRequest::with_uri("/name/user1/?id=test")
let req = TestRequest::with_uri("/name/user1/?id=test")
.finish_with_router(router.clone());
let info = router.recognize(&req).unwrap().1;
let req = req.with_route_info(info);
Expand Down
5 changes: 1 addition & 4 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::fmt::Write;
use std::fs::{DirEntry, File, Metadata};
use std::io::{Read, Seek};
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::path::{Path, PathBuf};
use std::time::{SystemTime, UNIX_EPOCH};
Expand All @@ -20,9 +19,7 @@ use mime_guess::{get_mime_type, guess_mime_type};
use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};

use error::Error;
use handler::{
AsyncResult, AsyncResultItem, Handler, Responder, RouteHandler, WrapHandler,
};
use handler::{AsyncResult, Handler, Responder, RouteHandler, WrapHandler};
use header;
use http::{ContentEncoding, Method, StatusCode};
use httpmessage::HttpMessage;
Expand Down
1 change: 0 additions & 1 deletion src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use http::StatusCode;
use httprequest::HttpRequest;
use httpresponse::HttpResponse;
use resource::ResourceHandler;
use server::Request;

/// Trait defines object that could be registered as route handler
#[allow(unused_variables)]
Expand Down
10 changes: 3 additions & 7 deletions src/httpmessage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use error::{
use header::Header;
use json::JsonBody;
use multipart::Multipart;
use payload::Payload;

/// Trait that implements general purpose operations on http messages
pub trait HttpMessage: Sized {
Expand Down Expand Up @@ -613,10 +612,7 @@ mod tests {
use encoding::all::ISO_8859_2;
use encoding::Encoding;
use futures::Async;
use http::{Method, Uri, Version};
use httprequest::HttpRequest;
use mime;
use std::str::FromStr;
use test::TestRequest;

#[test]
Expand Down Expand Up @@ -765,7 +761,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",
).header(header::CONTENT_LENGTH, "11")
Expand All @@ -780,7 +776,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",
).header(header::CONTENT_LENGTH, "11")
Expand Down Expand Up @@ -818,7 +814,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() {
Expand Down
38 changes: 10 additions & 28 deletions src/httprequest.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
//! HTTP Request message related code.
use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cell::{Ref, RefMut};
use std::collections::HashMap;
use std::net::SocketAddr;
use std::ops::Deref;
use std::rc::Rc;
use std::{cmp, fmt, io, str};
use std::{fmt, str};

use bytes::Bytes;
use cookie::Cookie;
use failure;
use futures::{Async, Poll, Stream};
use futures_cpupool::CpuPool;
use http::{header, HeaderMap, Method, StatusCode, Uri, Version};
use tokio_io::AsyncRead;
use url::{form_urlencoded, Url};

use body::Body;
use error::{CookieParseError, PayloadError, UrlGenerationError};
use error::{CookieParseError, UrlGenerationError};
use extensions::Extensions;
use handler::FromRequest;
use httpmessage::HttpMessage;
use httpresponse::{HttpResponse, HttpResponseBuilder};
use info::ConnectionInfo;
use param::Params;
use payload::Payload;
use router::{Resource, RouteInfo, Router};
use server::message::{MessageFlags, Request};
use uri::Url as InnerUrl;
use router::{Resource, RouteInfo};
use server::Request;

struct Query(HashMap<String, String>);
struct Cookies(Vec<Cookie<'static>>);

#[derive(Debug, Copy, Clone, PartialEq)]
pub(crate) enum RouterResource {
Notset,
Normal(u16),
}

/// An HTTP Request
pub struct HttpRequest<S = ()> {
req: Rc<Request>,
Expand Down Expand Up @@ -167,11 +156,6 @@ impl<S> HttpRequest<S> {
self.request().inner.url.path()
}

#[inline]
pub(crate) fn url(&self) -> &InnerUrl {
&self.request().inner.url
}

/// Get *ConnectionInfo* for the correct request.
#[inline]
pub fn connection_info(&self) -> Ref<ConnectionInfo> {
Expand Down Expand Up @@ -248,7 +232,6 @@ impl<S> HttpRequest<S> {
for (key, val) in form_urlencoded::parse(self.query_string().as_ref()) {
query.insert(key.as_ref().to_string(), val.to_string());
}
let mut req = self.clone();
self.extensions_mut().insert(Query(query));
}
Ref::map(self.extensions(), |ext| &ext.get::<Query>().unwrap().0)
Expand All @@ -270,7 +253,6 @@ impl<S> HttpRequest<S> {
#[inline]
pub fn cookies(&self) -> Result<Ref<Vec<Cookie<'static>>>, CookieParseError> {
if self.extensions().get::<Cookies>().is_none() {
let mut req = self.clone();
let mut cookies = Vec::new();
for hdr in self.request().inner.headers.get_all(header::COOKIE) {
let s = str::from_utf8(hdr.as_bytes()).map_err(CookieParseError::from)?;
Expand Down Expand Up @@ -379,7 +361,7 @@ impl<S> fmt::Debug for HttpRequest<S> {
mod tests {
use super::*;
use resource::ResourceHandler;
use router::Resource;
use router::{Resource, Router};
use test::TestRequest;

#[test]
Expand Down Expand Up @@ -448,7 +430,7 @@ mod tests {
let routes =
vec![(Resource::new("index", "/user/{name}.{ext}"), Some(resource))];
let (router, _) = Router::new("/", routes);
let info = router.default_route_info(0);
let info = router.default_route_info();
assert!(info.has_route("/user/test.html"));
assert!(!info.has_route("/test/unknown"));

Expand Down Expand Up @@ -476,7 +458,7 @@ mod tests {
resource.name("index");
let routes = vec![(Resource::new("index", "/user/{name}.html"), Some(resource))];
let (router, _) = Router::new("/prefix/", routes);
let info = router.default_route_info(0);
let info = router.default_route_info();
assert!(info.has_route("/user/test.html"));
assert!(!info.has_route("/prefix/user/test.html"));

Expand All @@ -495,7 +477,7 @@ mod tests {
resource.name("index");
let routes = vec![(Resource::new("index", "/index.html"), Some(resource))];
let (router, _) = Router::new("/prefix/", routes);
let info = router.default_route_info(0);
let info = router.default_route_info();
assert!(info.has_route("/index.html"));
assert!(!info.has_route("/prefix/index.html"));

Expand All @@ -518,7 +500,7 @@ mod tests {
None,
)];
let router = Router::new::<()>("", routes).0;
let info = router.default_route_info(0);
let info = router.default_route_info();
assert!(!info.has_route("https://youtube.com/watch/unknown"));

let req = TestRequest::default().finish_with_router(router);
Expand Down
2 changes: 0 additions & 2 deletions src/httpresponse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,6 @@ mod tests {
use body::Binary;
use http;
use http::header::{HeaderValue, CONTENT_TYPE, COOKIE};
use http::{Method, Uri};
use std::str::FromStr;
use time::Duration;

use test::TestRequest;
Expand Down
8 changes: 1 addition & 7 deletions src/info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use std::rc::Rc;
use std::str::FromStr;

use http::header::{self, HeaderName};
use httpmessage::HttpMessage;
use httprequest::HttpRequest;
use server::Request;

const X_FORWARDED_FOR: &[u8] = b"x-forwarded-for";
Expand Down Expand Up @@ -165,7 +160,6 @@ impl ConnectionInfo {
#[cfg(test)]
mod tests {
use super::*;
use http::header::HeaderValue;
use test::TestRequest;

#[test]
Expand Down Expand Up @@ -214,7 +208,7 @@ mod tests {
assert_eq!(info.host(), "192.0.2.60");
assert_eq!(info.remote(), None);

let mut req = TestRequest::default()
let req = TestRequest::default()
.header(X_FORWARDED_PROTO, "https")
.request();
let mut info = ConnectionInfo::default();
Expand Down
4 changes: 2 additions & 2 deletions src/json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bytes::{Bytes, BytesMut};
use bytes::BytesMut;
use futures::{Future, Poll, Stream};
use http::header::CONTENT_LENGTH;
use std::fmt;
Expand All @@ -10,7 +10,7 @@ use serde::de::DeserializeOwned;
use serde::Serialize;
use serde_json;

use error::{Error, JsonPayloadError, PayloadError};
use error::{Error, JsonPayloadError};
use handler::{FromRequest, Responder};
use http::StatusCode;
use httpmessage::HttpMessage;
Expand Down
Loading

0 comments on commit 6fd686e

Please sign in to comment.