mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-30 18:42:52 +01:00
clippy fmt
This commit is contained in:
parent
e9c139bdea
commit
1716380f08
@ -776,8 +776,7 @@ mod tests {
|
|||||||
.route("/test", Method::GET, |_: HttpRequest| HttpResponse::Ok())
|
.route("/test", Method::GET, |_: HttpRequest| HttpResponse::Ok())
|
||||||
.route("/test", Method::POST, |_: HttpRequest| {
|
.route("/test", Method::POST, |_: HttpRequest| {
|
||||||
HttpResponse::Created()
|
HttpResponse::Created()
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/test").method(Method::GET).request();
|
let req = TestRequest::with_uri("/test").method(Method::GET).request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
|
@ -768,8 +768,7 @@ impl ClientConnector {
|
|||||||
).map_err(move |_, act, _| {
|
).map_err(move |_, act, _| {
|
||||||
act.release_key(&key2);
|
act.release_key(&key2);
|
||||||
()
|
()
|
||||||
})
|
}).and_then(move |res, act, _| {
|
||||||
.and_then(move |res, act, _| {
|
|
||||||
#[cfg(feature = "alpn")]
|
#[cfg(feature = "alpn")]
|
||||||
match res {
|
match res {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -791,8 +790,7 @@ impl ClientConnector {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
let _ =
|
let _ = waiter.tx.send(Ok(Connection::new(
|
||||||
waiter.tx.send(Ok(Connection::new(
|
|
||||||
conn.0.clone(),
|
conn.0.clone(),
|
||||||
Some(conn),
|
Some(conn),
|
||||||
Box::new(stream),
|
Box::new(stream),
|
||||||
@ -834,8 +832,7 @@ impl ClientConnector {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
let _ =
|
let _ = waiter.tx.send(Ok(Connection::new(
|
||||||
waiter.tx.send(Ok(Connection::new(
|
|
||||||
conn.0.clone(),
|
conn.0.clone(),
|
||||||
Some(conn),
|
Some(conn),
|
||||||
Box::new(stream),
|
Box::new(stream),
|
||||||
@ -870,8 +867,7 @@ impl ClientConnector {
|
|||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
act.stats.opened += 1;
|
act.stats.opened += 1;
|
||||||
if conn.0.ssl {
|
if conn.0.ssl {
|
||||||
let host =
|
let host = DNSNameRef::try_from_ascii_str(&key.host).unwrap();
|
||||||
DNSNameRef::try_from_ascii_str(&key.host).unwrap();
|
|
||||||
fut::Either::A(
|
fut::Either::A(
|
||||||
act.connector
|
act.connector
|
||||||
.connect_async(host, stream)
|
.connect_async(host, stream)
|
||||||
@ -884,8 +880,7 @@ impl ClientConnector {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
let _ =
|
let _ = waiter.tx.send(Ok(Connection::new(
|
||||||
waiter.tx.send(Ok(Connection::new(
|
|
||||||
conn.0.clone(),
|
conn.0.clone(),
|
||||||
Some(conn),
|
Some(conn),
|
||||||
Box::new(stream),
|
Box::new(stream),
|
||||||
@ -915,9 +910,8 @@ impl ClientConnector {
|
|||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
act.stats.opened += 1;
|
act.stats.opened += 1;
|
||||||
if conn.0.ssl {
|
if conn.0.ssl {
|
||||||
let _ = waiter
|
let _ =
|
||||||
.tx
|
waiter.tx.send(Err(ClientConnectorError::SslIsNotSupported));
|
||||||
.send(Err(ClientConnectorError::SslIsNotSupported));
|
|
||||||
} else {
|
} else {
|
||||||
let _ = waiter.tx.send(Ok(Connection::new(
|
let _ = waiter.tx.send(Ok(Connection::new(
|
||||||
conn.0.clone(),
|
conn.0.clone(),
|
||||||
@ -928,8 +922,7 @@ impl ClientConnector {
|
|||||||
fut::ok(())
|
fut::ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}).spawn(ctx);
|
||||||
.spawn(ctx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,10 +302,9 @@ fn content_encoder(buf: BytesMut, req: &mut ClientRequest) -> Output {
|
|||||||
req.replace_body(body);
|
req.replace_body(body);
|
||||||
let enc = match encoding {
|
let enc = match encoding {
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "flate2")]
|
||||||
ContentEncoding::Deflate => ContentEncoder::Deflate(ZlibEncoder::new(
|
ContentEncoding::Deflate => {
|
||||||
transfer,
|
ContentEncoder::Deflate(ZlibEncoder::new(transfer, Compression::default()))
|
||||||
Compression::default(),
|
}
|
||||||
)),
|
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "flate2")]
|
||||||
ContentEncoding::Gzip => {
|
ContentEncoding::Gzip => {
|
||||||
ContentEncoder::Gzip(GzEncoder::new(transfer, Compression::default()))
|
ContentEncoder::Gzip(GzEncoder::new(transfer, Compression::default()))
|
||||||
|
16
src/fs.rs
16
src/fs.rs
@ -369,11 +369,7 @@ impl<C: StaticFileConfig> Responder for NamedFile<C> {
|
|||||||
.body("This resource only supports GET and HEAD."));
|
.body("This resource only supports GET and HEAD."));
|
||||||
}
|
}
|
||||||
|
|
||||||
let etag = if C::is_use_etag() {
|
let etag = if C::is_use_etag() { self.etag() } else { None };
|
||||||
self.etag()
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
let last_modified = if C::is_use_last_modifier() {
|
let last_modified = if C::is_use_last_modifier() {
|
||||||
self.last_modified()
|
self.last_modified()
|
||||||
} else {
|
} else {
|
||||||
@ -518,7 +514,8 @@ impl Stream for ChunkedReadFile {
|
|||||||
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 = 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.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?;
|
let nbytes =
|
||||||
|
file.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?;
|
||||||
if nbytes == 0 {
|
if nbytes == 0 {
|
||||||
return Err(io::ErrorKind::UnexpectedEof.into());
|
return Err(io::ErrorKind::UnexpectedEof.into());
|
||||||
}
|
}
|
||||||
@ -869,8 +866,7 @@ impl HttpRange {
|
|||||||
length: length as u64,
|
length: length as u64,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
})
|
}).collect::<Result<_, _>>()?;
|
||||||
.collect::<Result<_, _>>()?;
|
|
||||||
|
|
||||||
let ranges: Vec<HttpRange> = all_ranges.into_iter().filter_map(|x| x).collect();
|
let ranges: Vec<HttpRange> = all_ranges.into_iter().filter_map(|x| x).collect();
|
||||||
|
|
||||||
@ -986,9 +982,7 @@ mod tests {
|
|||||||
use header::{ContentDisposition, DispositionParam, DispositionType};
|
use header::{ContentDisposition, DispositionParam, DispositionType};
|
||||||
let cd = ContentDisposition {
|
let cd = ContentDisposition {
|
||||||
disposition: DispositionType::Attachment,
|
disposition: DispositionType::Attachment,
|
||||||
parameters: vec![DispositionParam::Filename(
|
parameters: vec![DispositionParam::Filename(String::from("test.png"))],
|
||||||
String::from("test.png")
|
|
||||||
)],
|
|
||||||
};
|
};
|
||||||
let mut file = NamedFile::open("tests/test.png")
|
let mut file = NamedFile::open("tests/test.png")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -354,15 +354,16 @@ impl<T, E: Into<Error>> From<Result<T, E>> for AsyncResult<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> From<Result<Box<Future<Item = T, Error = E>>, E>> for AsyncResult<T>
|
impl<T, E> From<Result<Box<Future<Item = T, Error = E>>, E>> for AsyncResult<T>
|
||||||
where T: 'static,
|
where
|
||||||
E: Into<Error> + 'static
|
T: 'static,
|
||||||
|
E: Into<Error> + 'static,
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(res: Result<Box<Future<Item = T, Error = E>>, E>) -> Self {
|
fn from(res: Result<Box<Future<Item = T, Error = E>>, E>) -> Self {
|
||||||
match res {
|
match res {
|
||||||
Ok(fut) => AsyncResult(
|
Ok(fut) => AsyncResult(Some(AsyncResultItem::Future(Box::new(
|
||||||
Some(AsyncResultItem::Future(
|
fut.map_err(|e| e.into()),
|
||||||
Box::new(fut.map_err(|e| e.into()))))),
|
)))),
|
||||||
Err(err) => AsyncResult(Some(AsyncResultItem::Err(err.into()))),
|
Err(err) => AsyncResult(Some(AsyncResultItem::Err(err.into()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,8 +223,7 @@ pub fn from_comma_delimited<T: FromStr>(
|
|||||||
.filter_map(|x| match x.trim() {
|
.filter_map(|x| match x.trim() {
|
||||||
"" => None,
|
"" => None,
|
||||||
y => Some(y),
|
y => Some(y),
|
||||||
})
|
}).filter_map(|x| x.trim().parse().ok()),
|
||||||
.filter_map(|x| x.trim().parse().ok()),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
@ -279,8 +279,7 @@ mod tests {
|
|||||||
true,
|
true,
|
||||||
StatusCode::MOVED_PERMANENTLY,
|
StatusCode::MOVED_PERMANENTLY,
|
||||||
))
|
))
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
// trailing slashes
|
// trailing slashes
|
||||||
let params = vec![
|
let params = vec![
|
||||||
|
@ -479,8 +479,7 @@ where
|
|||||||
body.extend_from_slice(&chunk);
|
body.extend_from_slice(&chunk);
|
||||||
Ok(body)
|
Ok(body)
|
||||||
}
|
}
|
||||||
})
|
}).map(|body| body.freeze()),
|
||||||
.map(|body| body.freeze()),
|
|
||||||
));
|
));
|
||||||
self.poll()
|
self.poll()
|
||||||
}
|
}
|
||||||
@ -588,8 +587,7 @@ where
|
|||||||
body.extend_from_slice(&chunk);
|
body.extend_from_slice(&chunk);
|
||||||
Ok(body)
|
Ok(body)
|
||||||
}
|
}
|
||||||
})
|
}).and_then(move |body| {
|
||||||
.and_then(move |body| {
|
|
||||||
if (encoding as *const Encoding) == UTF_8 {
|
if (encoding as *const Encoding) == UTF_8 {
|
||||||
serde_urlencoded::from_bytes::<U>(&body)
|
serde_urlencoded::from_bytes::<U>(&body)
|
||||||
.map_err(|_| UrlencodedError::Parse)
|
.map_err(|_| UrlencodedError::Parse)
|
||||||
@ -694,8 +692,7 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::TRANSFER_ENCODING,
|
header::TRANSFER_ENCODING,
|
||||||
Bytes::from_static(b"some va\xadscc\xacas0xsdasdlue"),
|
Bytes::from_static(b"some va\xadscc\xacas0xsdasdlue"),
|
||||||
)
|
).finish();
|
||||||
.finish();
|
|
||||||
assert!(req.chunked().is_err());
|
assert!(req.chunked().is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -830,8 +827,7 @@ mod tests {
|
|||||||
b"Lorem Ipsum is simply dummy text of the printing and typesetting\n\
|
b"Lorem Ipsum is simply dummy text of the printing and typesetting\n\
|
||||||
industry. Lorem Ipsum has been the industry's standard dummy\n\
|
industry. Lorem Ipsum has been the industry's standard dummy\n\
|
||||||
Contrary to popular belief, Lorem Ipsum is not simply random text.",
|
Contrary to popular belief, Lorem Ipsum is not simply random text.",
|
||||||
))
|
)).finish();
|
||||||
.finish();
|
|
||||||
let mut r = Readlines::new(&req);
|
let mut r = Readlines::new(&req);
|
||||||
match r.poll().ok().unwrap() {
|
match r.poll().ok().unwrap() {
|
||||||
Async::Ready(Some(s)) => assert_eq!(
|
Async::Ready(Some(s)) => assert_eq!(
|
||||||
|
@ -264,7 +264,8 @@ impl<S> HttpRequest<S> {
|
|||||||
if self.extensions().get::<Cookies>().is_none() {
|
if self.extensions().get::<Cookies>().is_none() {
|
||||||
let mut cookies = Vec::new();
|
let mut cookies = Vec::new();
|
||||||
for hdr in self.request().inner.headers.get_all(header::COOKIE) {
|
for hdr in self.request().inner.headers.get_all(header::COOKIE) {
|
||||||
let s = str::from_utf8(hdr.as_bytes()).map_err(CookieParseError::from)?;
|
let s =
|
||||||
|
str::from_utf8(hdr.as_bytes()).map_err(CookieParseError::from)?;
|
||||||
for cookie_str in s.split(';').map(|s| s.trim()) {
|
for cookie_str in s.split(';').map(|s| s.trim()) {
|
||||||
if !cookie_str.is_empty() {
|
if !cookie_str.is_empty() {
|
||||||
cookies.push(Cookie::parse_encoded(cookie_str)?.into_owned());
|
cookies.push(Cookie::parse_encoded(cookie_str)?.into_owned());
|
||||||
|
@ -142,8 +142,7 @@ impl HttpResponse {
|
|||||||
HeaderValue::from_str(&cookie.to_string())
|
HeaderValue::from_str(&cookie.to_string())
|
||||||
.map(|c| {
|
.map(|c| {
|
||||||
h.append(header::SET_COOKIE, c);
|
h.append(header::SET_COOKIE, c);
|
||||||
})
|
}).map_err(|e| e.into())
|
||||||
.map_err(|e| e.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove all cookies with the given name from this response. Returns
|
/// Remove all cookies with the given name from this response. Returns
|
||||||
@ -1079,8 +1078,7 @@ mod tests {
|
|||||||
.http_only(true)
|
.http_only(true)
|
||||||
.max_age(Duration::days(1))
|
.max_age(Duration::days(1))
|
||||||
.finish(),
|
.finish(),
|
||||||
)
|
).del_cookie(&cookies[0])
|
||||||
.del_cookie(&cookies[0])
|
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
let mut val: Vec<_> = resp
|
let mut val: Vec<_> = resp
|
||||||
|
@ -174,8 +174,7 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::FORWARDED,
|
header::FORWARDED,
|
||||||
"for=192.0.2.60; proto=https; by=203.0.113.43; host=rust-lang.org",
|
"for=192.0.2.60; proto=https; by=203.0.113.43; host=rust-lang.org",
|
||||||
)
|
).request();
|
||||||
.request();
|
|
||||||
|
|
||||||
let mut info = ConnectionInfo::default();
|
let mut info = ConnectionInfo::default();
|
||||||
info.update(&req);
|
info.update(&req);
|
||||||
|
21
src/json.rs
21
src/json.rs
@ -327,8 +327,7 @@ impl<T: HttpMessage + 'static, U: DeserializeOwned + 'static> Future for JsonBod
|
|||||||
body.extend_from_slice(&chunk);
|
body.extend_from_slice(&chunk);
|
||||||
Ok(body)
|
Ok(body)
|
||||||
}
|
}
|
||||||
})
|
}).and_then(|body| Ok(serde_json::from_slice::<U>(&body)?));
|
||||||
.and_then(|body| Ok(serde_json::from_slice::<U>(&body)?));
|
|
||||||
self.fut = Some(Box::new(fut));
|
self.fut = Some(Box::new(fut));
|
||||||
self.poll()
|
self.poll()
|
||||||
}
|
}
|
||||||
@ -388,8 +387,7 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
header::HeaderValue::from_static("application/text"),
|
header::HeaderValue::from_static("application/text"),
|
||||||
)
|
).finish();
|
||||||
.finish();
|
|
||||||
let mut json = req.json::<MyObject>();
|
let mut json = req.json::<MyObject>();
|
||||||
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::ContentType);
|
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::ContentType);
|
||||||
|
|
||||||
@ -397,12 +395,10 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
header::HeaderValue::from_static("application/json"),
|
header::HeaderValue::from_static("application/json"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::CONTENT_LENGTH,
|
header::CONTENT_LENGTH,
|
||||||
header::HeaderValue::from_static("10000"),
|
header::HeaderValue::from_static("10000"),
|
||||||
)
|
).finish();
|
||||||
.finish();
|
|
||||||
let mut json = req.json::<MyObject>().limit(100);
|
let mut json = req.json::<MyObject>().limit(100);
|
||||||
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::Overflow);
|
assert_eq!(json.poll().err().unwrap(), JsonPayloadError::Overflow);
|
||||||
|
|
||||||
@ -410,12 +406,10 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::CONTENT_TYPE,
|
header::CONTENT_TYPE,
|
||||||
header::HeaderValue::from_static("application/json"),
|
header::HeaderValue::from_static("application/json"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::CONTENT_LENGTH,
|
header::CONTENT_LENGTH,
|
||||||
header::HeaderValue::from_static("16"),
|
header::HeaderValue::from_static("16"),
|
||||||
)
|
).set_payload(Bytes::from_static(b"{\"name\": \"test\"}"))
|
||||||
.set_payload(Bytes::from_static(b"{\"name\": \"test\"}"))
|
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
let mut json = req.json::<MyObject>();
|
let mut json = req.json::<MyObject>();
|
||||||
@ -442,8 +436,7 @@ mod tests {
|
|||||||
).header(
|
).header(
|
||||||
header::CONTENT_LENGTH,
|
header::CONTENT_LENGTH,
|
||||||
header::HeaderValue::from_static("16"),
|
header::HeaderValue::from_static("16"),
|
||||||
)
|
).set_payload(Bytes::from_static(b"{\"name\": \"test\"}"))
|
||||||
.set_payload(Bytes::from_static(b"{\"name\": \"test\"}"))
|
|
||||||
.finish();
|
.finish();
|
||||||
assert!(handler.handle(&req).as_err().is_none())
|
assert!(handler.handle(&req).as_err().is_none())
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,6 @@ extern crate tokio_uds;
|
|||||||
extern crate url;
|
extern crate url;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_urlencoded;
|
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
extern crate brotli2;
|
extern crate brotli2;
|
||||||
extern crate encoding;
|
extern crate encoding;
|
||||||
@ -135,6 +134,7 @@ extern crate encoding;
|
|||||||
extern crate flate2;
|
extern crate flate2;
|
||||||
extern crate h2 as http2;
|
extern crate h2 as http2;
|
||||||
extern crate num_cpus;
|
extern crate num_cpus;
|
||||||
|
extern crate serde_urlencoded;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate percent_encoding;
|
extern crate percent_encoding;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
@ -256,12 +256,12 @@ pub mod dev {
|
|||||||
pub use extractor::{FormConfig, PayloadConfig};
|
pub use extractor::{FormConfig, PayloadConfig};
|
||||||
pub use handler::{AsyncResult, Handler};
|
pub use handler::{AsyncResult, Handler};
|
||||||
pub use httpmessage::{MessageBody, Readlines, UrlEncoded};
|
pub use httpmessage::{MessageBody, Readlines, UrlEncoded};
|
||||||
pub use pipeline::Pipeline;
|
|
||||||
pub use httpresponse::HttpResponseBuilder;
|
pub use httpresponse::HttpResponseBuilder;
|
||||||
pub use info::ConnectionInfo;
|
pub use info::ConnectionInfo;
|
||||||
pub use json::{JsonBody, JsonConfig};
|
pub use json::{JsonBody, JsonConfig};
|
||||||
pub use param::{FromParam, Params};
|
pub use param::{FromParam, Params};
|
||||||
pub use payload::{Payload, PayloadBuffer};
|
pub use payload::{Payload, PayloadBuffer};
|
||||||
|
pub use pipeline::Pipeline;
|
||||||
pub use resource::Resource;
|
pub use resource::Resource;
|
||||||
pub use route::Route;
|
pub use route::Route;
|
||||||
pub use router::{ResourceDef, ResourceInfo, ResourceType, Router};
|
pub use router::{ResourceDef, ResourceInfo, ResourceType, Router};
|
||||||
@ -283,7 +283,9 @@ pub mod http {
|
|||||||
/// Various http headers
|
/// Various http headers
|
||||||
pub mod header {
|
pub mod header {
|
||||||
pub use header::*;
|
pub use header::*;
|
||||||
pub use header::{ContentDisposition, DispositionType, DispositionParam, Charset, LanguageTag};
|
pub use header::{
|
||||||
|
Charset, ContentDisposition, DispositionParam, DispositionType, LanguageTag,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
pub use header::ContentEncoding;
|
pub use header::ContentEncoding;
|
||||||
pub use httpresponse::ConnectionType;
|
pub use httpresponse::ConnectionType;
|
||||||
|
@ -387,12 +387,10 @@ impl<S> Middleware<S> for Cors {
|
|||||||
header::ACCESS_CONTROL_MAX_AGE,
|
header::ACCESS_CONTROL_MAX_AGE,
|
||||||
format!("{}", max_age).as_str(),
|
format!("{}", max_age).as_str(),
|
||||||
);
|
);
|
||||||
})
|
}).if_some(headers, |headers, resp| {
|
||||||
.if_some(headers, |headers, resp| {
|
|
||||||
let _ =
|
let _ =
|
||||||
resp.header(header::ACCESS_CONTROL_ALLOW_HEADERS, headers);
|
resp.header(header::ACCESS_CONTROL_ALLOW_HEADERS, headers);
|
||||||
})
|
}).if_true(self.inner.origins.is_all(), |resp| {
|
||||||
.if_true(self.inner.origins.is_all(), |resp| {
|
|
||||||
if self.inner.send_wildcard {
|
if self.inner.send_wildcard {
|
||||||
resp.header(header::ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
resp.header(header::ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||||
} else {
|
} else {
|
||||||
@ -402,17 +400,14 @@ impl<S> Middleware<S> for Cors {
|
|||||||
origin.clone(),
|
origin.clone(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
}).if_true(self.inner.origins.is_some(), |resp| {
|
||||||
.if_true(self.inner.origins.is_some(), |resp| {
|
|
||||||
resp.header(
|
resp.header(
|
||||||
header::ACCESS_CONTROL_ALLOW_ORIGIN,
|
header::ACCESS_CONTROL_ALLOW_ORIGIN,
|
||||||
self.inner.origins_str.as_ref().unwrap().clone(),
|
self.inner.origins_str.as_ref().unwrap().clone(),
|
||||||
);
|
);
|
||||||
})
|
}).if_true(self.inner.supports_credentials, |resp| {
|
||||||
.if_true(self.inner.supports_credentials, |resp| {
|
|
||||||
resp.header(header::ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
|
resp.header(header::ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
|
||||||
})
|
}).header(
|
||||||
.header(
|
|
||||||
header::ACCESS_CONTROL_ALLOW_METHODS,
|
header::ACCESS_CONTROL_ALLOW_METHODS,
|
||||||
&self
|
&self
|
||||||
.inner
|
.inner
|
||||||
@ -420,8 +415,7 @@ impl<S> Middleware<S> for Cors {
|
|||||||
.iter()
|
.iter()
|
||||||
.fold(String::new(), |s, v| s + "," + v.as_str())
|
.fold(String::new(), |s, v| s + "," + v.as_str())
|
||||||
.as_str()[1..],
|
.as_str()[1..],
|
||||||
)
|
).finish(),
|
||||||
.finish(),
|
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
// Only check requests with a origin header.
|
// Only check requests with a origin header.
|
||||||
@ -838,9 +832,10 @@ impl<S: 'static> CorsBuilder<S> {
|
|||||||
|
|
||||||
if !self.expose_hdrs.is_empty() {
|
if !self.expose_hdrs.is_empty() {
|
||||||
cors.expose_hdrs = Some(
|
cors.expose_hdrs = Some(
|
||||||
self.expose_hdrs.iter()
|
self.expose_hdrs
|
||||||
|
.iter()
|
||||||
.fold(String::new(), |s, v| format!("{}, {}", s, v.as_str()))[2..]
|
.fold(String::new(), |s, v| format!("{}, {}", s, v.as_str()))[2..]
|
||||||
.to_owned()
|
.to_owned(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Cors {
|
Cors {
|
||||||
@ -977,8 +972,7 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::ACCESS_CONTROL_REQUEST_HEADERS,
|
header::ACCESS_CONTROL_REQUEST_HEADERS,
|
||||||
"AUTHORIZATION,ACCEPT",
|
"AUTHORIZATION,ACCEPT",
|
||||||
)
|
).method(Method::OPTIONS)
|
||||||
.method(Method::OPTIONS)
|
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
let resp = cors.start(&req).unwrap().response();
|
let resp = cors.start(&req).unwrap().response();
|
||||||
@ -1102,7 +1096,8 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
{
|
{
|
||||||
let headers = resp.headers()
|
let headers = resp
|
||||||
|
.headers()
|
||||||
.get(header::ACCESS_CONTROL_EXPOSE_HEADERS)
|
.get(header::ACCESS_CONTROL_EXPOSE_HEADERS)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_str()
|
.to_str()
|
||||||
|
@ -93,8 +93,7 @@ fn origin(headers: &HeaderMap) -> Option<Result<Cow<str>, CsrfError>> {
|
|||||||
.to_str()
|
.to_str()
|
||||||
.map_err(|_| CsrfError::BadOrigin)
|
.map_err(|_| CsrfError::BadOrigin)
|
||||||
.map(|o| o.into())
|
.map(|o| o.into())
|
||||||
})
|
}).or_else(|| {
|
||||||
.or_else(|| {
|
|
||||||
headers.get(header::REFERER).map(|referer| {
|
headers.get(header::REFERER).map(|referer| {
|
||||||
Uri::try_from(Bytes::from(referer.as_bytes()))
|
Uri::try_from(Bytes::from(referer.as_bytes()))
|
||||||
.ok()
|
.ok()
|
||||||
|
@ -579,8 +579,7 @@ mod tests {
|
|||||||
App::new()
|
App::new()
|
||||||
.middleware(SessionStorage::new(
|
.middleware(SessionStorage::new(
|
||||||
CookieSessionBackend::signed(&[0; 32]).secure(false),
|
CookieSessionBackend::signed(&[0; 32]).secure(false),
|
||||||
))
|
)).resource("/", |r| {
|
||||||
.resource("/", |r| {
|
|
||||||
r.f(|req| {
|
r.f(|req| {
|
||||||
let _ = req.session().set("counter", 100);
|
let _ = req.session().set("counter", 100);
|
||||||
"test"
|
"test"
|
||||||
@ -599,8 +598,7 @@ mod tests {
|
|||||||
App::new()
|
App::new()
|
||||||
.middleware(SessionStorage::new(
|
.middleware(SessionStorage::new(
|
||||||
CookieSessionBackend::signed(&[0; 32]).secure(false),
|
CookieSessionBackend::signed(&[0; 32]).secure(false),
|
||||||
))
|
)).resource("/", |r| {
|
||||||
.resource("/", |r| {
|
|
||||||
r.with(|ses: Session| {
|
r.with(|ses: Session| {
|
||||||
let _ = ses.set("counter", 100);
|
let _ = ses.set("counter", 100);
|
||||||
"test"
|
"test"
|
||||||
|
@ -756,10 +756,7 @@ mod tests {
|
|||||||
{
|
{
|
||||||
use http::header::{DispositionParam, DispositionType};
|
use http::header::{DispositionParam, DispositionType};
|
||||||
let cd = field.content_disposition().unwrap();
|
let cd = field.content_disposition().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(cd.disposition, DispositionType::FormData);
|
||||||
cd.disposition,
|
|
||||||
DispositionType::FormData
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cd.parameters[0],
|
cd.parameters[0],
|
||||||
DispositionParam::Name("file".into())
|
DispositionParam::Name("file".into())
|
||||||
@ -813,7 +810,6 @@ mod tests {
|
|||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
}))
|
})).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -513,8 +513,7 @@ where
|
|||||||
.fold(BytesMut::new(), |mut b, c| {
|
.fold(BytesMut::new(), |mut b, c| {
|
||||||
b.extend_from_slice(c);
|
b.extend_from_slice(c);
|
||||||
b
|
b
|
||||||
})
|
}).freeze()
|
||||||
.freeze()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,8 +552,7 @@ mod tests {
|
|||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
}))
|
})).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -578,8 +576,7 @@ mod tests {
|
|||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
}))
|
})).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -596,8 +593,7 @@ mod tests {
|
|||||||
payload.readany().err().unwrap();
|
payload.readany().err().unwrap();
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
}))
|
})).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -625,8 +621,7 @@ mod tests {
|
|||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
}))
|
})).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -659,8 +654,7 @@ mod tests {
|
|||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
}))
|
})).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -693,8 +687,7 @@ mod tests {
|
|||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
}))
|
})).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -715,7 +708,6 @@ mod tests {
|
|||||||
|
|
||||||
let res: Result<(), ()> = Ok(());
|
let res: Result<(), ()> = Ok(());
|
||||||
result(res)
|
result(res)
|
||||||
}))
|
})).unwrap();
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
121
src/pipeline.rs
121
src/pipeline.rs
@ -52,9 +52,7 @@ impl<S: 'static, H: PipelineHandler<S>> PipelineState<S, H> {
|
|||||||
PipelineState::Finishing(ref mut state) => state.poll(info, mws),
|
PipelineState::Finishing(ref mut state) => state.poll(info, mws),
|
||||||
PipelineState::Completed(ref mut state) => state.poll(info),
|
PipelineState::Completed(ref mut state) => state.poll(info),
|
||||||
PipelineState::Response(ref mut state) => state.poll(info, mws),
|
PipelineState::Response(ref mut state) => state.poll(info, mws),
|
||||||
PipelineState::None | PipelineState::Error => {
|
PipelineState::None | PipelineState::Error => None,
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -448,10 +446,16 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
) -> Option<PipelineState<S, H>> {
|
) -> Option<PipelineState<S, H>> {
|
||||||
// connection is dead at this point
|
// connection is dead at this point
|
||||||
match mem::replace(&mut self.iostate, IOState::Done) {
|
match mem::replace(&mut self.iostate, IOState::Done) {
|
||||||
IOState::Response =>
|
IOState::Response => Some(FinishingMiddlewares::init(
|
||||||
Some(FinishingMiddlewares::init(info, mws, self.resp.take().unwrap())),
|
info,
|
||||||
IOState::Payload(_) =>
|
mws,
|
||||||
Some(FinishingMiddlewares::init(info, mws, self.resp.take().unwrap())),
|
self.resp.take().unwrap(),
|
||||||
|
)),
|
||||||
|
IOState::Payload(_) => Some(FinishingMiddlewares::init(
|
||||||
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
|
)),
|
||||||
IOState::Actor(mut ctx) => {
|
IOState::Actor(mut ctx) => {
|
||||||
if info.disconnected.take().is_some() {
|
if info.disconnected.take().is_some() {
|
||||||
ctx.disconnected();
|
ctx.disconnected();
|
||||||
@ -467,18 +471,25 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
Frame::Chunk(None) => {
|
Frame::Chunk(None) => {
|
||||||
info.context = Some(ctx);
|
info.context = Some(ctx);
|
||||||
return Some(FinishingMiddlewares::init(
|
return Some(FinishingMiddlewares::init(
|
||||||
info, mws, self.resp.take().unwrap(),
|
info,
|
||||||
))
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
Frame::Chunk(Some(_)) => (),
|
Frame::Chunk(Some(_)) => (),
|
||||||
Frame::Drain(fut) => {let _ = fut.send(());},
|
Frame::Drain(fut) => {
|
||||||
|
let _ = fut.send(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Async::Ready(None)) =>
|
}
|
||||||
|
Ok(Async::Ready(None)) => {
|
||||||
return Some(FinishingMiddlewares::init(
|
return Some(FinishingMiddlewares::init(
|
||||||
info, mws, self.resp.take().unwrap(),
|
info,
|
||||||
)),
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
|
))
|
||||||
|
}
|
||||||
Ok(Async::NotReady) => {
|
Ok(Async::NotReady) => {
|
||||||
self.iostate = IOState::Actor(ctx);
|
self.iostate = IOState::Actor(ctx);
|
||||||
return None;
|
return None;
|
||||||
@ -486,12 +497,20 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
info.context = Some(ctx);
|
info.context = Some(ctx);
|
||||||
info.error = Some(err);
|
info.error = Some(err);
|
||||||
return Some(FinishingMiddlewares::init(info, mws, self.resp.take().unwrap()));
|
return Some(FinishingMiddlewares::init(
|
||||||
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IOState::Done => Some(FinishingMiddlewares::init(info, mws, self.resp.take().unwrap()))
|
IOState::Done => Some(FinishingMiddlewares::init(
|
||||||
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,22 +524,32 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
'inner: loop {
|
'inner: loop {
|
||||||
let result = match mem::replace(&mut self.iostate, IOState::Done) {
|
let result = match mem::replace(&mut self.iostate, IOState::Done) {
|
||||||
IOState::Response => {
|
IOState::Response => {
|
||||||
let encoding =
|
let encoding = self
|
||||||
self.resp.as_ref().unwrap().content_encoding().unwrap_or(info.encoding);
|
.resp
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.content_encoding()
|
||||||
|
.unwrap_or(info.encoding);
|
||||||
|
|
||||||
let result =
|
let result = match io.start(
|
||||||
match io.start(&info.req, self.resp.as_mut().unwrap(), encoding) {
|
&info.req,
|
||||||
|
self.resp.as_mut().unwrap(),
|
||||||
|
encoding,
|
||||||
|
) {
|
||||||
Ok(res) => res,
|
Ok(res) => res,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
info.error = Some(err.into());
|
info.error = Some(err.into());
|
||||||
return Ok(FinishingMiddlewares::init(
|
return Ok(FinishingMiddlewares::init(
|
||||||
info, mws, self.resp.take().unwrap(),
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(err) = self.resp.as_ref().unwrap().error() {
|
if let Some(err) = self.resp.as_ref().unwrap().error() {
|
||||||
if self.resp.as_ref().unwrap().status().is_server_error() {
|
if self.resp.as_ref().unwrap().status().is_server_error()
|
||||||
|
{
|
||||||
error!(
|
error!(
|
||||||
"Error occured during request handling, status: {} {}",
|
"Error occured during request handling, status: {} {}",
|
||||||
self.resp.as_ref().unwrap().status(), err
|
self.resp.as_ref().unwrap().status(), err
|
||||||
@ -556,7 +585,9 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
if let Err(err) = io.write_eof() {
|
if let Err(err) = io.write_eof() {
|
||||||
info.error = Some(err.into());
|
info.error = Some(err.into());
|
||||||
return Ok(FinishingMiddlewares::init(
|
return Ok(FinishingMiddlewares::init(
|
||||||
info, mws, self.resp.take().unwrap(),
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -567,7 +598,9 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
info.error = Some(err.into());
|
info.error = Some(err.into());
|
||||||
return Ok(FinishingMiddlewares::init(
|
return Ok(FinishingMiddlewares::init(
|
||||||
info, mws, self.resp.take().unwrap(),
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
@ -580,7 +613,9 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
info.error = Some(err);
|
info.error = Some(err);
|
||||||
return Ok(FinishingMiddlewares::init(
|
return Ok(FinishingMiddlewares::init(
|
||||||
info, mws, self.resp.take().unwrap(),
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -603,26 +638,30 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
info.error = Some(err.into());
|
info.error = Some(err.into());
|
||||||
return Ok(
|
return Ok(
|
||||||
FinishingMiddlewares::init(
|
FinishingMiddlewares::init(
|
||||||
info, mws, self.resp.take().unwrap(),
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break 'inner;
|
break 'inner;
|
||||||
}
|
}
|
||||||
Frame::Chunk(Some(chunk)) => {
|
Frame::Chunk(Some(chunk)) => match io
|
||||||
match io.write(&chunk) {
|
.write(&chunk)
|
||||||
|
{
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
info.context = Some(ctx);
|
info.context = Some(ctx);
|
||||||
info.error = Some(err.into());
|
info.error = Some(err.into());
|
||||||
return Ok(
|
return Ok(
|
||||||
FinishingMiddlewares::init(
|
FinishingMiddlewares::init(
|
||||||
info, mws, self.resp.take().unwrap(),
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(result) => res = Some(result),
|
Ok(result) => res = Some(result),
|
||||||
}
|
},
|
||||||
}
|
|
||||||
Frame::Drain(fut) => self.drain = Some(fut),
|
Frame::Drain(fut) => self.drain = Some(fut),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -642,7 +681,9 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
info.context = Some(ctx);
|
info.context = Some(ctx);
|
||||||
info.error = Some(err);
|
info.error = Some(err);
|
||||||
return Ok(FinishingMiddlewares::init(
|
return Ok(FinishingMiddlewares::init(
|
||||||
info, mws, self.resp.take().unwrap(),
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -682,7 +723,11 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
info.context = Some(ctx);
|
info.context = Some(ctx);
|
||||||
}
|
}
|
||||||
info.error = Some(err.into());
|
info.error = Some(err.into());
|
||||||
return Ok(FinishingMiddlewares::init(info, mws, self.resp.take().unwrap()));
|
return Ok(FinishingMiddlewares::init(
|
||||||
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -696,11 +741,19 @@ impl<S: 'static, H> ProcessResponse<S, H> {
|
|||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
info.error = Some(err.into());
|
info.error = Some(err.into());
|
||||||
return Ok(FinishingMiddlewares::init(info, mws, self.resp.take().unwrap()));
|
return Ok(FinishingMiddlewares::init(
|
||||||
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.resp.as_mut().unwrap().set_response_size(io.written());
|
self.resp.as_mut().unwrap().set_response_size(io.written());
|
||||||
Ok(FinishingMiddlewares::init(info, mws, self.resp.take().unwrap()))
|
Ok(FinishingMiddlewares::init(
|
||||||
|
info,
|
||||||
|
mws,
|
||||||
|
self.resp.take().unwrap(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
_ => Err(PipelineState::Response(self)),
|
_ => Err(PipelineState::Response(self)),
|
||||||
}
|
}
|
||||||
|
@ -264,8 +264,7 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::HOST,
|
header::HOST,
|
||||||
header::HeaderValue::from_static("www.rust-lang.org"),
|
header::HeaderValue::from_static("www.rust-lang.org"),
|
||||||
)
|
).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let pred = Host("www.rust-lang.org");
|
let pred = Host("www.rust-lang.org");
|
||||||
assert!(pred.check(&req, req.state()));
|
assert!(pred.check(&req, req.state()));
|
||||||
|
66
src/scope.rs
66
src/scope.rs
@ -715,8 +715,7 @@ mod tests {
|
|||||||
let app = App::new()
|
let app = App::new()
|
||||||
.scope("/app", |scope| {
|
.scope("/app", |scope| {
|
||||||
scope.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
scope.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/path1").request();
|
let req = TestRequest::with_uri("/app/path1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -730,8 +729,7 @@ mod tests {
|
|||||||
scope
|
scope
|
||||||
.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/", |r| r.f(|_| HttpResponse::Created()))
|
.resource("/", |r| r.f(|_| HttpResponse::Created()))
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app").request();
|
let req = TestRequest::with_uri("/app").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -747,8 +745,7 @@ mod tests {
|
|||||||
let app = App::new()
|
let app = App::new()
|
||||||
.scope("/app/", |scope| {
|
.scope("/app/", |scope| {
|
||||||
scope.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
scope.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app").request();
|
let req = TestRequest::with_uri("/app").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -764,8 +761,7 @@ mod tests {
|
|||||||
let app = App::new()
|
let app = App::new()
|
||||||
.scope("/app/", |scope| {
|
.scope("/app/", |scope| {
|
||||||
scope.resource("/", |r| r.f(|_| HttpResponse::Ok()))
|
scope.resource("/", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app").request();
|
let req = TestRequest::with_uri("/app").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -783,12 +779,12 @@ mod tests {
|
|||||||
scope
|
scope
|
||||||
.route("/path1", Method::GET, |_: HttpRequest<_>| {
|
.route("/path1", Method::GET, |_: HttpRequest<_>| {
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
})
|
}).route(
|
||||||
.route("/path1", Method::DELETE, |_: HttpRequest<_>| {
|
"/path1",
|
||||||
HttpResponse::Ok()
|
Method::DELETE,
|
||||||
})
|
|_: HttpRequest<_>| HttpResponse::Ok(),
|
||||||
})
|
)
|
||||||
.finish();
|
}).finish();
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/path1").request();
|
let req = TestRequest::with_uri("/app/path1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -814,8 +810,7 @@ mod tests {
|
|||||||
scope
|
scope
|
||||||
.filter(pred::Get())
|
.filter(pred::Get())
|
||||||
.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/path1")
|
let req = TestRequest::with_uri("/app/path1")
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
@ -840,8 +835,7 @@ mod tests {
|
|||||||
.body(format!("project: {}", &r.match_info()["project"]))
|
.body(format!("project: {}", &r.match_info()["project"]))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/ab-project1/path1").request();
|
let req = TestRequest::with_uri("/ab-project1/path1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -869,8 +863,7 @@ mod tests {
|
|||||||
scope.with_state("/t1", State, |scope| {
|
scope.with_state("/t1", State, |scope| {
|
||||||
scope.resource("/path1", |r| r.f(|_| HttpResponse::Created()))
|
scope.resource("/path1", |r| r.f(|_| HttpResponse::Created()))
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/t1/path1").request();
|
let req = TestRequest::with_uri("/app/t1/path1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -888,8 +881,7 @@ mod tests {
|
|||||||
.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/", |r| r.f(|_| HttpResponse::Created()))
|
.resource("/", |r| r.f(|_| HttpResponse::Created()))
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/t1").request();
|
let req = TestRequest::with_uri("/app/t1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -909,8 +901,7 @@ mod tests {
|
|||||||
scope.with_state("/t1/", State, |scope| {
|
scope.with_state("/t1/", State, |scope| {
|
||||||
scope.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
scope.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/t1").request();
|
let req = TestRequest::with_uri("/app/t1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -930,8 +921,7 @@ mod tests {
|
|||||||
scope.with_state("/t1/", State, |scope| {
|
scope.with_state("/t1/", State, |scope| {
|
||||||
scope.resource("/", |r| r.f(|_| HttpResponse::Ok()))
|
scope.resource("/", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/t1").request();
|
let req = TestRequest::with_uri("/app/t1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -953,8 +943,7 @@ mod tests {
|
|||||||
.filter(pred::Get())
|
.filter(pred::Get())
|
||||||
.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/t1/path1")
|
let req = TestRequest::with_uri("/app/t1/path1")
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
@ -976,8 +965,7 @@ mod tests {
|
|||||||
scope.nested("/t1", |scope| {
|
scope.nested("/t1", |scope| {
|
||||||
scope.resource("/path1", |r| r.f(|_| HttpResponse::Created()))
|
scope.resource("/path1", |r| r.f(|_| HttpResponse::Created()))
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/t1/path1").request();
|
let req = TestRequest::with_uri("/app/t1/path1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -993,8 +981,7 @@ mod tests {
|
|||||||
.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
.resource("", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/", |r| r.f(|_| HttpResponse::Created()))
|
.resource("/", |r| r.f(|_| HttpResponse::Created()))
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/t1").request();
|
let req = TestRequest::with_uri("/app/t1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -1014,8 +1001,7 @@ mod tests {
|
|||||||
.filter(pred::Get())
|
.filter(pred::Get())
|
||||||
.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/t1/path1")
|
let req = TestRequest::with_uri("/app/t1/path1")
|
||||||
.method(Method::POST)
|
.method(Method::POST)
|
||||||
@ -1044,8 +1030,7 @@ mod tests {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/project_1/path1").request();
|
let req = TestRequest::with_uri("/app/project_1/path1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -1077,8 +1062,7 @@ mod tests {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/test/1/path1").request();
|
let req = TestRequest::with_uri("/app/test/1/path1").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -1104,8 +1088,7 @@ mod tests {
|
|||||||
scope
|
scope
|
||||||
.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
.resource("/path1", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.default_resource(|r| r.f(|_| HttpResponse::BadRequest()))
|
.default_resource(|r| r.f(|_| HttpResponse::BadRequest()))
|
||||||
})
|
}).finish();
|
||||||
.finish();
|
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/app/path2").request();
|
let req = TestRequest::with_uri("/app/path2").request();
|
||||||
let resp = app.run(req);
|
let resp = app.run(req);
|
||||||
@ -1121,8 +1104,7 @@ mod tests {
|
|||||||
let app = App::new()
|
let app = App::new()
|
||||||
.scope("/app1", |scope| {
|
.scope("/app1", |scope| {
|
||||||
scope.default_resource(|r| r.f(|_| HttpResponse::BadRequest()))
|
scope.default_resource(|r| r.f(|_| HttpResponse::BadRequest()))
|
||||||
})
|
}).scope("/app2", |scope| scope)
|
||||||
.scope("/app2", |scope| scope)
|
|
||||||
.default_resource(|r| r.f(|_| HttpResponse::MethodNotAllowed()))
|
.default_resource(|r| r.f(|_| HttpResponse::MethodNotAllowed()))
|
||||||
.finish();
|
.finish();
|
||||||
|
|
||||||
|
@ -166,8 +166,8 @@ impl H1Decoder {
|
|||||||
{
|
{
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
version == Version::HTTP_11
|
version == Version::HTTP_11 && !(conn
|
||||||
&& !(conn.contains("close")
|
.contains("close")
|
||||||
|| conn.contains("upgrade"))
|
|| conn.contains("upgrade"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,8 +152,7 @@ impl<T: AsyncWrite, H: 'static> Writer for H1Writer<T, H> {
|
|||||||
let reason = msg.reason().as_bytes();
|
let reason = msg.reason().as_bytes();
|
||||||
if let Body::Binary(ref bytes) = body {
|
if let Body::Binary(ref bytes) = body {
|
||||||
buffer.reserve(
|
buffer.reserve(
|
||||||
256
|
256 + msg.headers().len() * AVERAGE_HEADER_SIZE
|
||||||
+ msg.headers().len() * AVERAGE_HEADER_SIZE
|
|
||||||
+ bytes.len()
|
+ bytes.len()
|
||||||
+ reason.len(),
|
+ reason.len(),
|
||||||
);
|
);
|
||||||
|
@ -129,7 +129,8 @@ where
|
|||||||
not_ready = false;
|
not_ready = false;
|
||||||
}
|
}
|
||||||
Ok(Async::NotReady) => {
|
Ok(Async::NotReady) => {
|
||||||
if item.payload.need_read() == PayloadStatus::Read
|
if item.payload.need_read()
|
||||||
|
== PayloadStatus::Read
|
||||||
&& !retry
|
&& !retry
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -150,11 +151,15 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if item.flags.contains(EntryFlags::EOF) && !item.flags.contains(EntryFlags::FINISHED) {
|
if item.flags.contains(EntryFlags::EOF)
|
||||||
|
&& !item.flags.contains(EntryFlags::FINISHED)
|
||||||
|
{
|
||||||
match item.task.poll_completed() {
|
match item.task.poll_completed() {
|
||||||
Ok(Async::NotReady) => (),
|
Ok(Async::NotReady) => (),
|
||||||
Ok(Async::Ready(_)) => {
|
Ok(Async::Ready(_)) => {
|
||||||
item.flags.insert(EntryFlags::FINISHED | EntryFlags::WRITE_DONE);
|
item.flags.insert(
|
||||||
|
EntryFlags::FINISHED | EntryFlags::WRITE_DONE,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
item.flags.insert(
|
item.flags.insert(
|
||||||
|
@ -250,9 +250,7 @@ impl<H: 'static> Writer for H2Writer<H> {
|
|||||||
return Ok(Async::Ready(()));
|
return Ok(Async::Ready(()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e)),
|
||||||
return Err(io::Error::new(io::ErrorKind::Other, e))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -403,19 +403,24 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<H: IntoHttpHandler> Into<(Box<Service>, Vec<(Token, net::TcpListener)>)> for HttpServer<H> {
|
impl<H: IntoHttpHandler> Into<(Box<Service>, Vec<(Token, net::TcpListener)>)>
|
||||||
|
for HttpServer<H>
|
||||||
|
{
|
||||||
fn into(mut self) -> (Box<Service>, Vec<(Token, net::TcpListener)>) {
|
fn into(mut self) -> (Box<Service>, Vec<(Token, net::TcpListener)>) {
|
||||||
let sockets: Vec<_> = mem::replace(&mut self.sockets, Vec::new())
|
let sockets: Vec<_> = mem::replace(&mut self.sockets, Vec::new())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|item| (item.token, item.lst))
|
.map(|item| (item.token, item.lst))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
(Box::new(HttpService {
|
(
|
||||||
|
Box::new(HttpService {
|
||||||
factory: self.factory,
|
factory: self.factory,
|
||||||
host: self.host,
|
host: self.host,
|
||||||
keep_alive: self.keep_alive,
|
keep_alive: self.keep_alive,
|
||||||
handlers: self.handlers,
|
handlers: self.handlers,
|
||||||
}), sockets)
|
}),
|
||||||
|
sockets,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,12 +125,12 @@ mod h1writer;
|
|||||||
mod h2;
|
mod h2;
|
||||||
mod h2writer;
|
mod h2writer;
|
||||||
pub(crate) mod helpers;
|
pub(crate) mod helpers;
|
||||||
|
mod http;
|
||||||
pub(crate) mod input;
|
pub(crate) mod input;
|
||||||
pub(crate) mod message;
|
pub(crate) mod message;
|
||||||
pub(crate) mod output;
|
pub(crate) mod output;
|
||||||
mod server;
|
mod server;
|
||||||
pub(crate) mod settings;
|
pub(crate) mod settings;
|
||||||
mod http;
|
|
||||||
mod ssl;
|
mod ssl;
|
||||||
mod worker;
|
mod worker;
|
||||||
|
|
||||||
@ -138,12 +138,12 @@ use actix::Message;
|
|||||||
|
|
||||||
pub use self::message::Request;
|
pub use self::message::Request;
|
||||||
|
|
||||||
|
pub use self::http::HttpServer;
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use self::server::{
|
pub use self::server::{
|
||||||
ConnectionRateTag, ConnectionTag, Connections, Server, Service, ServiceHandler,
|
ConnectionRateTag, ConnectionTag, Connections, Server, Service, ServiceHandler,
|
||||||
};
|
};
|
||||||
pub use self::settings::ServerSettings;
|
pub use self::settings::ServerSettings;
|
||||||
pub use self::http::HttpServer;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub use self::ssl::*;
|
pub use self::ssl::*;
|
||||||
|
@ -273,10 +273,9 @@ impl Output {
|
|||||||
|
|
||||||
let enc = match encoding {
|
let enc = match encoding {
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "flate2")]
|
||||||
ContentEncoding::Deflate => ContentEncoder::Deflate(ZlibEncoder::new(
|
ContentEncoding::Deflate => {
|
||||||
transfer,
|
ContentEncoder::Deflate(ZlibEncoder::new(transfer, Compression::fast()))
|
||||||
Compression::fast(),
|
}
|
||||||
)),
|
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(feature = "flate2")]
|
||||||
ContentEncoding::Gzip => {
|
ContentEncoding::Gzip => {
|
||||||
ContentEncoder::Gzip(GzEncoder::new(transfer, Compression::fast()))
|
ContentEncoder::Gzip(GzEncoder::new(transfer, Compression::fast()))
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
use std::{mem, net};
|
use std::sync::{
|
||||||
|
atomic::{AtomicUsize, Ordering},
|
||||||
|
Arc,
|
||||||
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
|
use std::{mem, net};
|
||||||
|
|
||||||
use num_cpus;
|
|
||||||
use futures::{Future, Stream, Sink};
|
|
||||||
use futures::sync::{mpsc, mpsc::unbounded};
|
use futures::sync::{mpsc, mpsc::unbounded};
|
||||||
|
use futures::{Future, Sink, Stream};
|
||||||
|
use num_cpus;
|
||||||
|
|
||||||
use actix::{fut, signal, Actor, ActorFuture, Addr, Arbiter, AsyncContext,
|
use actix::{
|
||||||
Context, Handler, Response, System, StreamHandler, WrapFuture};
|
fut, signal, Actor, ActorFuture, Addr, Arbiter, AsyncContext, Context, Handler,
|
||||||
|
Response, StreamHandler, System, WrapFuture,
|
||||||
|
};
|
||||||
|
|
||||||
use super::accept::{AcceptLoop, AcceptNotify, Command};
|
use super::accept::{AcceptLoop, AcceptNotify, Command};
|
||||||
use super::worker::{StopWorker, Worker, WorkerClient, Conn};
|
use super::worker::{Conn, StopWorker, Worker, WorkerClient};
|
||||||
use super::{PauseServer, ResumeServer, StopServer, Token};
|
use super::{PauseServer, ResumeServer, StopServer, Token};
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
@ -39,7 +44,9 @@ impl Service for Box<Service> {
|
|||||||
/// TCP connections.
|
/// TCP connections.
|
||||||
pub trait ServiceHandler {
|
pub trait ServiceHandler {
|
||||||
/// Handle incoming stream
|
/// Handle incoming stream
|
||||||
fn handle(&mut self, token: Token, io: net::TcpStream, peer: Option<net::SocketAddr>);
|
fn handle(
|
||||||
|
&mut self, token: Token, io: net::TcpStream, peer: Option<net::SocketAddr>,
|
||||||
|
);
|
||||||
|
|
||||||
/// Shutdown open handlers
|
/// Shutdown open handlers
|
||||||
fn shutdown(&self, _: bool) {}
|
fn shutdown(&self, _: bool) {}
|
||||||
@ -156,7 +163,7 @@ impl Server {
|
|||||||
/// Add new service to server
|
/// Add new service to server
|
||||||
pub fn service<T>(mut self, srv: T) -> Self
|
pub fn service<T>(mut self, srv: T) -> Self
|
||||||
where
|
where
|
||||||
T: Into<(Box<Service>, Vec<(Token, net::TcpListener)>)>
|
T: Into<(Box<Service>, Vec<(Token, net::TcpListener)>)>,
|
||||||
{
|
{
|
||||||
let (srv, sockets) = srv.into();
|
let (srv, sockets) = srv.into();
|
||||||
self.services.push(srv);
|
self.services.push(srv);
|
||||||
@ -213,8 +220,9 @@ impl Server {
|
|||||||
info!("Starting server on http://{:?}", s.1.local_addr().ok());
|
info!("Starting server on http://{:?}", s.1.local_addr().ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let rx = self.accept.start(
|
let rx = self
|
||||||
mem::replace(&mut self.sockets, Vec::new()), workers);
|
.accept
|
||||||
|
.start(mem::replace(&mut self.sockets, Vec::new()), workers);
|
||||||
|
|
||||||
// start http server actor
|
// start http server actor
|
||||||
let signals = self.subscribe_to_signals();
|
let signals = self.subscribe_to_signals();
|
||||||
@ -242,7 +250,9 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_worker(&self, idx: usize, notify: AcceptNotify) -> (Addr<Worker>, WorkerClient) {
|
fn start_worker(
|
||||||
|
&self, idx: usize, notify: AcceptNotify,
|
||||||
|
) -> (Addr<Worker>, WorkerClient) {
|
||||||
let (tx, rx) = unbounded::<Conn<net::TcpStream>>();
|
let (tx, rx) = unbounded::<Conn<net::TcpStream>>();
|
||||||
let conns = Connections::new(notify, self.maxconn, self.maxconnrate);
|
let conns = Connections::new(notify, self.maxconn, self.maxconnrate);
|
||||||
let worker = WorkerClient::new(idx, tx, conns.clone());
|
let worker = WorkerClient::new(idx, tx, conns.clone());
|
||||||
@ -250,7 +260,10 @@ impl Server {
|
|||||||
|
|
||||||
let addr = Arbiter::start(move |ctx: &mut Context<_>| {
|
let addr = Arbiter::start(move |ctx: &mut Context<_>| {
|
||||||
ctx.add_message_stream(rx);
|
ctx.add_message_stream(rx);
|
||||||
let handlers: Vec<_> = services.into_iter().map(|s| s.create(conns.clone())).collect();
|
let handlers: Vec<_> = services
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| s.create(conns.clone()))
|
||||||
|
.collect();
|
||||||
Worker::new(conns, handlers)
|
Worker::new(conns, handlers)
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -258,8 +271,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Actor for Server
|
impl Actor for Server {
|
||||||
{
|
|
||||||
type Context = Context<Self>;
|
type Context = Context<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,7 +403,8 @@ impl StreamHandler<ServerCommand, ()> for Server {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (addr, worker) = self.start_worker(new_idx, self.accept.get_notify());
|
let (addr, worker) =
|
||||||
|
self.start_worker(new_idx, self.accept.get_notify());
|
||||||
self.workers.push((new_idx, addr));
|
self.workers.push((new_idx, addr));
|
||||||
self.accept.send(Command::Worker(worker));
|
self.accept.send(Command::Worker(worker));
|
||||||
}
|
}
|
||||||
@ -413,11 +426,12 @@ impl Connections {
|
|||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
Connections (
|
Connections(Arc::new(ConnectionsInner {
|
||||||
Arc::new(ConnectionsInner {
|
|
||||||
notify,
|
notify,
|
||||||
maxconn, maxconnrate,
|
maxconn,
|
||||||
maxconn_low, maxconnrate_low,
|
maxconnrate,
|
||||||
|
maxconn_low,
|
||||||
|
maxconnrate_low,
|
||||||
conn: AtomicUsize::new(0),
|
conn: AtomicUsize::new(0),
|
||||||
connrate: AtomicUsize::new(0),
|
connrate: AtomicUsize::new(0),
|
||||||
}))
|
}))
|
||||||
@ -473,7 +487,6 @@ impl ConnectionsInner {
|
|||||||
self.notify.notify();
|
self.notify.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Type responsible for max connection stat.
|
/// Type responsible for max connection stat.
|
||||||
|
@ -6,7 +6,7 @@ pub use self::openssl::OpensslAcceptor;
|
|||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
mod nativetls;
|
mod nativetls;
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "tls")]
|
||||||
pub use self::nativetls::{TlsStream, NativeTlsAcceptor};
|
pub use self::nativetls::{NativeTlsAcceptor, TlsStream};
|
||||||
|
|
||||||
#[cfg(feature = "rust-tls")]
|
#[cfg(feature = "rust-tls")]
|
||||||
mod rustls;
|
mod rustls;
|
||||||
|
@ -2,7 +2,7 @@ use std::net::Shutdown;
|
|||||||
use std::{io, time};
|
use std::{io, time};
|
||||||
|
|
||||||
use futures::{Async, Future, Poll};
|
use futures::{Async, Future, Poll};
|
||||||
use native_tls::{self, TlsAcceptor, HandshakeError};
|
use native_tls::{self, HandshakeError, TlsAcceptor};
|
||||||
use tokio_io::{AsyncRead, AsyncWrite};
|
use tokio_io::{AsyncRead, AsyncWrite};
|
||||||
|
|
||||||
use server::{AcceptorService, IoStream};
|
use server::{AcceptorService, IoStream};
|
||||||
@ -36,7 +36,9 @@ pub struct Accept<S>{
|
|||||||
impl NativeTlsAcceptor {
|
impl NativeTlsAcceptor {
|
||||||
/// Create `NativeTlsAcceptor` instance
|
/// Create `NativeTlsAcceptor` instance
|
||||||
pub fn new(acceptor: TlsAcceptor) -> Self {
|
pub fn new(acceptor: TlsAcceptor) -> Self {
|
||||||
NativeTlsAcceptor { acceptor: acceptor.into() }
|
NativeTlsAcceptor {
|
||||||
|
acceptor: acceptor.into(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +51,9 @@ impl<Io: IoStream> AcceptorService<Io> for NativeTlsAcceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn accept(&self, io: Io) -> Self::Future {
|
fn accept(&self, io: Io) -> Self::Future {
|
||||||
Accept { inner: Some(self.acceptor.accept(io)) }
|
Accept {
|
||||||
|
inner: Some(self.acceptor.accept(io)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,18 +82,19 @@ impl<Io: IoStream> Future for Accept<Io> {
|
|||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
match self.inner.take().expect("cannot poll MidHandshake twice") {
|
match self.inner.take().expect("cannot poll MidHandshake twice") {
|
||||||
Ok(stream) => Ok(TlsStream { inner: stream }.into()),
|
Ok(stream) => Ok(TlsStream { inner: stream }.into()),
|
||||||
Err(HandshakeError::Failure(e)) => Err(io::Error::new(io::ErrorKind::Other, e)),
|
Err(HandshakeError::Failure(e)) => {
|
||||||
Err(HandshakeError::WouldBlock(s)) => {
|
Err(io::Error::new(io::ErrorKind::Other, e))
|
||||||
match s.handshake() {
|
}
|
||||||
|
Err(HandshakeError::WouldBlock(s)) => match s.handshake() {
|
||||||
Ok(stream) => Ok(TlsStream { inner: stream }.into()),
|
Ok(stream) => Ok(TlsStream { inner: stream }.into()),
|
||||||
Err(HandshakeError::Failure(e)) =>
|
Err(HandshakeError::Failure(e)) => {
|
||||||
Err(io::Error::new(io::ErrorKind::Other, e)),
|
Err(io::Error::new(io::ErrorKind::Other, e))
|
||||||
|
}
|
||||||
Err(HandshakeError::WouldBlock(s)) => {
|
Err(HandshakeError::WouldBlock(s)) => {
|
||||||
self.inner = Some(Err(HandshakeError::WouldBlock(s)));
|
self.inner = Some(Err(HandshakeError::WouldBlock(s)));
|
||||||
Ok(Async::NotReady)
|
Ok(Async::NotReady)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,9 +129,7 @@ impl<S: io::Read + io::Write> io::Write for TlsStream<S> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S: AsyncRead + AsyncWrite> AsyncRead for TlsStream<S> {}
|
||||||
impl<S: AsyncRead + AsyncWrite> AsyncRead for TlsStream<S> {
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S: AsyncRead + AsyncWrite> AsyncWrite for TlsStream<S> {
|
impl<S: AsyncRead + AsyncWrite> AsyncWrite for TlsStream<S> {
|
||||||
fn shutdown(&mut self) -> Poll<(), io::Error> {
|
fn shutdown(&mut self) -> Poll<(), io::Error> {
|
||||||
|
53
src/with.rs
53
src/with.rs
@ -20,7 +20,8 @@ impl<T, R, F: Fn(T) -> R + 'static> FnWith<T, R> for F {
|
|||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait WithFactory<T, S, R>: 'static
|
pub trait WithFactory<T, S, R>: 'static
|
||||||
where T: FromRequest<S>,
|
where
|
||||||
|
T: FromRequest<S>,
|
||||||
R: Responder,
|
R: Responder,
|
||||||
{
|
{
|
||||||
fn create(self) -> With<T, S, R>;
|
fn create(self) -> With<T, S, R>;
|
||||||
@ -30,7 +31,8 @@ where T: FromRequest<S>,
|
|||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait WithAsyncFactory<T, S, R, I, E>: 'static
|
pub trait WithAsyncFactory<T, S, R, I, E>: 'static
|
||||||
where T: FromRequest<S>,
|
where
|
||||||
|
T: FromRequest<S>,
|
||||||
R: Future<Item = I, Error = E>,
|
R: Future<Item = I, Error = E>,
|
||||||
I: Responder,
|
I: Responder,
|
||||||
E: Into<Error>,
|
E: Into<Error>,
|
||||||
@ -305,7 +307,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
macro_rules! with_factory_tuple ({$(($n:tt, $T:ident)),+} => {
|
macro_rules! with_factory_tuple ({$(($n:tt, $T:ident)),+} => {
|
||||||
impl<$($T,)+ State, Func, Res> WithFactory<($($T,)+), State, Res> for Func
|
impl<$($T,)+ State, Func, Res> WithFactory<($($T,)+), State, Res> for Func
|
||||||
where Func: Fn($($T,)+) -> Res + 'static,
|
where Func: Fn($($T,)+) -> Res + 'static,
|
||||||
@ -349,8 +350,27 @@ with_factory_tuple!((a, A), (b, B), (c, C), (d, D));
|
|||||||
with_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E));
|
with_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E));
|
||||||
with_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F));
|
with_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F));
|
||||||
with_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F), (g, G));
|
with_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F), (g, G));
|
||||||
with_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F), (g, G), (h, H));
|
with_factory_tuple!(
|
||||||
with_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F), (g, G), (h, H), (i, I));
|
(a, A),
|
||||||
|
(b, B),
|
||||||
|
(c, C),
|
||||||
|
(d, D),
|
||||||
|
(e, E),
|
||||||
|
(f, F),
|
||||||
|
(g, G),
|
||||||
|
(h, H)
|
||||||
|
);
|
||||||
|
with_factory_tuple!(
|
||||||
|
(a, A),
|
||||||
|
(b, B),
|
||||||
|
(c, C),
|
||||||
|
(d, D),
|
||||||
|
(e, E),
|
||||||
|
(f, F),
|
||||||
|
(g, G),
|
||||||
|
(h, H),
|
||||||
|
(i, I)
|
||||||
|
);
|
||||||
|
|
||||||
with_async_factory_tuple!((a, A));
|
with_async_factory_tuple!((a, A));
|
||||||
with_async_factory_tuple!((a, A), (b, B));
|
with_async_factory_tuple!((a, A), (b, B));
|
||||||
@ -359,5 +379,24 @@ with_async_factory_tuple!((a, A), (b, B), (c, C), (d, D));
|
|||||||
with_async_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E));
|
with_async_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E));
|
||||||
with_async_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F));
|
with_async_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F));
|
||||||
with_async_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F), (g, G));
|
with_async_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F), (g, G));
|
||||||
with_async_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F), (g, G), (h, H));
|
with_async_factory_tuple!(
|
||||||
with_async_factory_tuple!((a, A), (b, B), (c, C), (d, D), (e, E), (f, F), (g, G), (h, H), (i, I));
|
(a, A),
|
||||||
|
(b, B),
|
||||||
|
(c, C),
|
||||||
|
(d, D),
|
||||||
|
(e, E),
|
||||||
|
(f, F),
|
||||||
|
(g, G),
|
||||||
|
(h, H)
|
||||||
|
);
|
||||||
|
with_async_factory_tuple!(
|
||||||
|
(a, A),
|
||||||
|
(b, B),
|
||||||
|
(c, C),
|
||||||
|
(d, D),
|
||||||
|
(e, E),
|
||||||
|
(f, F),
|
||||||
|
(g, G),
|
||||||
|
(h, H),
|
||||||
|
(i, I)
|
||||||
|
);
|
||||||
|
@ -387,8 +387,7 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
).finish();
|
||||||
.finish();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::NoConnectionUpgrade,
|
HandshakeError::NoConnectionUpgrade,
|
||||||
handshake(&req).err().unwrap()
|
handshake(&req).err().unwrap()
|
||||||
@ -398,12 +397,10 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
).finish();
|
||||||
.finish();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::NoVersionHeader,
|
HandshakeError::NoVersionHeader,
|
||||||
handshake(&req).err().unwrap()
|
handshake(&req).err().unwrap()
|
||||||
@ -413,16 +410,13 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("5"),
|
header::HeaderValue::from_static("5"),
|
||||||
)
|
).finish();
|
||||||
.finish();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::UnsupportedVersion,
|
HandshakeError::UnsupportedVersion,
|
||||||
handshake(&req).err().unwrap()
|
handshake(&req).err().unwrap()
|
||||||
@ -432,16 +426,13 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
).finish();
|
||||||
.finish();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
HandshakeError::BadWebsocketKey,
|
HandshakeError::BadWebsocketKey,
|
||||||
handshake(&req).err().unwrap()
|
handshake(&req).err().unwrap()
|
||||||
@ -451,20 +442,16 @@ mod tests {
|
|||||||
.header(
|
.header(
|
||||||
header::UPGRADE,
|
header::UPGRADE,
|
||||||
header::HeaderValue::from_static("websocket"),
|
header::HeaderValue::from_static("websocket"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::CONNECTION,
|
header::CONNECTION,
|
||||||
header::HeaderValue::from_static("upgrade"),
|
header::HeaderValue::from_static("upgrade"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::SEC_WEBSOCKET_VERSION,
|
header::SEC_WEBSOCKET_VERSION,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
).header(
|
||||||
.header(
|
|
||||||
header::SEC_WEBSOCKET_KEY,
|
header::SEC_WEBSOCKET_KEY,
|
||||||
header::HeaderValue::from_static("13"),
|
header::HeaderValue::from_static("13"),
|
||||||
)
|
).finish();
|
||||||
.finish();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
StatusCode::SWITCHING_PROTOCOLS,
|
StatusCode::SWITCHING_PROTOCOLS,
|
||||||
handshake(&req).unwrap().finish().status()
|
handshake(&req).unwrap().finish().status()
|
||||||
|
@ -118,8 +118,7 @@ fn test_client_gzip_encoding() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Deflate)
|
.content_encoding(http::ContentEncoding::Deflate)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -148,8 +147,7 @@ fn test_client_gzip_encoding_large() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Deflate)
|
.content_encoding(http::ContentEncoding::Deflate)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -181,8 +179,7 @@ fn test_client_gzip_encoding_large_random() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Deflate)
|
.content_encoding(http::ContentEncoding::Deflate)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -200,7 +197,6 @@ fn test_client_gzip_encoding_large_random() {
|
|||||||
assert_eq!(bytes, Bytes::from(data));
|
assert_eq!(bytes, Bytes::from(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(all(unix, feature = "uds"))]
|
#[cfg(all(unix, feature = "uds"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_compatible_with_unix_socket_stream() {
|
fn test_compatible_with_unix_socket_stream() {
|
||||||
@ -218,8 +214,7 @@ fn test_client_brotli_encoding() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Gzip)
|
.content_encoding(http::ContentEncoding::Gzip)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -252,8 +247,7 @@ fn test_client_brotli_encoding_large_random() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Gzip)
|
.content_encoding(http::ContentEncoding::Gzip)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -282,8 +276,7 @@ fn test_client_deflate_encoding() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Br)
|
.content_encoding(http::ContentEncoding::Br)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -316,8 +309,7 @@ fn test_client_deflate_encoding_large_random() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Br)
|
.content_encoding(http::ContentEncoding::Br)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -346,8 +338,7 @@ fn test_client_streaming_explicit() {
|
|||||||
.chunked()
|
.chunked()
|
||||||
.content_encoding(http::ContentEncoding::Identity)
|
.content_encoding(http::ContentEncoding::Identity)
|
||||||
.body(body))
|
.body(body))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -191,8 +191,7 @@ fn test_form_extractor() {
|
|||||||
.uri(srv.url("/test1/index.html"))
|
.uri(srv.url("/test1/index.html"))
|
||||||
.form(FormData {
|
.form(FormData {
|
||||||
username: "test".to_string(),
|
username: "test".to_string(),
|
||||||
})
|
}).unwrap();
|
||||||
.unwrap();
|
|
||||||
let response = srv.execute(request.send()).unwrap();
|
let response = srv.execute(request.send()).unwrap();
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
|
|
||||||
@ -306,8 +305,7 @@ fn test_path_and_query_extractor2_async() {
|
|||||||
Delay::new(Instant::now() + Duration::from_millis(10))
|
Delay::new(Instant::now() + Duration::from_millis(10))
|
||||||
.and_then(move |_| {
|
.and_then(move |_| {
|
||||||
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -336,8 +334,7 @@ fn test_path_and_query_extractor3_async() {
|
|||||||
Delay::new(Instant::now() + Duration::from_millis(10))
|
Delay::new(Instant::now() + Duration::from_millis(10))
|
||||||
.and_then(move |_| {
|
.and_then(move |_| {
|
||||||
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -361,8 +358,7 @@ fn test_path_and_query_extractor4_async() {
|
|||||||
Delay::new(Instant::now() + Duration::from_millis(10))
|
Delay::new(Instant::now() + Duration::from_millis(10))
|
||||||
.and_then(move |_| {
|
.and_then(move |_| {
|
||||||
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -387,8 +383,7 @@ fn test_path_and_query_extractor2_async2() {
|
|||||||
Delay::new(Instant::now() + Duration::from_millis(10))
|
Delay::new(Instant::now() + Duration::from_millis(10))
|
||||||
.and_then(move |_| {
|
.and_then(move |_| {
|
||||||
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -422,15 +417,13 @@ fn test_path_and_query_extractor2_async2() {
|
|||||||
fn test_path_and_query_extractor2_async3() {
|
fn test_path_and_query_extractor2_async3() {
|
||||||
let mut srv = test::TestServer::new(|app| {
|
let mut srv = test::TestServer::new(|app| {
|
||||||
app.resource("/{username}/index.html", |r| {
|
app.resource("/{username}/index.html", |r| {
|
||||||
r.route().with(
|
r.route()
|
||||||
|data: Json<Value>, p: Path<PParam>, _: Query<PParam>| {
|
.with(|data: Json<Value>, p: Path<PParam>, _: Query<PParam>| {
|
||||||
Delay::new(Instant::now() + Duration::from_millis(10))
|
Delay::new(Instant::now() + Duration::from_millis(10))
|
||||||
.and_then(move |_| {
|
.and_then(move |_| {
|
||||||
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
Ok(format!("Welcome {} - {}!", p.username, data.0))
|
||||||
|
}).responder()
|
||||||
})
|
})
|
||||||
.responder()
|
|
||||||
},
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -467,8 +460,7 @@ fn test_path_and_query_extractor2_async4() {
|
|||||||
Delay::new(Instant::now() + Duration::from_millis(10))
|
Delay::new(Instant::now() + Duration::from_millis(10))
|
||||||
.and_then(move |_| {
|
.and_then(move |_| {
|
||||||
Ok(format!("Welcome {} - {}!", data.1.username, (data.0).0))
|
Ok(format!("Welcome {} - {}!", data.1.username, (data.0).0))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -87,8 +87,7 @@ fn test_middleware_multiple() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).handler(|_| HttpResponse::Ok())
|
||||||
.handler(|_| HttpResponse::Ok())
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let request = srv.get().finish().unwrap();
|
let request = srv.get().finish().unwrap();
|
||||||
@ -146,8 +145,7 @@ fn test_resource_middleware_multiple() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).handler(|_| HttpResponse::Ok())
|
||||||
.handler(|_| HttpResponse::Ok())
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let request = srv.get().finish().unwrap();
|
let request = srv.get().finish().unwrap();
|
||||||
@ -176,8 +174,7 @@ fn test_scope_middleware() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -207,13 +204,11 @@ fn test_scope_middleware_multiple() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).middleware(MiddlewareTest {
|
||||||
.middleware(MiddlewareTest {
|
|
||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -242,8 +237,7 @@ fn test_middleware_async_handler() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).resource("/", |r| {
|
||||||
.resource("/", |r| {
|
|
||||||
r.route().a(|_| {
|
r.route().a(|_| {
|
||||||
Delay::new(Instant::now() + Duration::from_millis(10))
|
Delay::new(Instant::now() + Duration::from_millis(10))
|
||||||
.and_then(|_| Ok(HttpResponse::Ok()))
|
.and_then(|_| Ok(HttpResponse::Ok()))
|
||||||
@ -312,8 +306,7 @@ fn test_scope_middleware_async_handler() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).resource("/test", |r| {
|
||||||
.resource("/test", |r| {
|
|
||||||
r.route().a(|_| {
|
r.route().a(|_| {
|
||||||
Delay::new(Instant::now() + Duration::from_millis(10))
|
Delay::new(Instant::now() + Duration::from_millis(10))
|
||||||
.and_then(|_| Ok(HttpResponse::Ok()))
|
.and_then(|_| Ok(HttpResponse::Ok()))
|
||||||
@ -379,8 +372,7 @@ fn test_scope_middleware_async_error() {
|
|||||||
start: Arc::clone(&act_req),
|
start: Arc::clone(&act_req),
|
||||||
response: Arc::clone(&act_resp),
|
response: Arc::clone(&act_resp),
|
||||||
finish: Arc::clone(&act_fin),
|
finish: Arc::clone(&act_fin),
|
||||||
})
|
}).resource("/test", |r| r.f(index_test_middleware_async_error))
|
||||||
.resource("/test", |r| r.f(index_test_middleware_async_error))
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -514,13 +506,11 @@ fn test_async_middleware_multiple() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).middleware(MiddlewareAsyncTest {
|
||||||
.middleware(MiddlewareAsyncTest {
|
|
||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let request = srv.get().uri(srv.url("/test")).finish().unwrap();
|
let request = srv.get().uri(srv.url("/test")).finish().unwrap();
|
||||||
@ -550,13 +540,11 @@ fn test_async_sync_middleware_multiple() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).middleware(MiddlewareTest {
|
||||||
.middleware(MiddlewareTest {
|
|
||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let request = srv.get().uri(srv.url("/test")).finish().unwrap();
|
let request = srv.get().uri(srv.url("/test")).finish().unwrap();
|
||||||
@ -587,8 +575,7 @@ fn test_async_scope_middleware() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -620,13 +607,11 @@ fn test_async_scope_middleware_multiple() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).middleware(MiddlewareAsyncTest {
|
||||||
.middleware(MiddlewareAsyncTest {
|
|
||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -658,13 +643,11 @@ fn test_async_async_scope_middleware_multiple() {
|
|||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).middleware(MiddlewareTest {
|
||||||
.middleware(MiddlewareTest {
|
|
||||||
start: Arc::clone(&act_num1),
|
start: Arc::clone(&act_num1),
|
||||||
response: Arc::clone(&act_num2),
|
response: Arc::clone(&act_num2),
|
||||||
finish: Arc::clone(&act_num3),
|
finish: Arc::clone(&act_num3),
|
||||||
})
|
}).resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
||||||
.resource("/test", |r| r.f(|_| HttpResponse::Ok()))
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1012,8 +995,7 @@ fn test_session_storage_middleware() {
|
|||||||
App::new()
|
App::new()
|
||||||
.middleware(SessionStorage::new(
|
.middleware(SessionStorage::new(
|
||||||
CookieSessionBackend::signed(&[0; 32]).secure(false),
|
CookieSessionBackend::signed(&[0; 32]).secure(false),
|
||||||
))
|
)).resource("/index", move |r| {
|
||||||
.resource("/index", move |r| {
|
|
||||||
r.f(|req| {
|
r.f(|req| {
|
||||||
let res = req.session().set(COMPLEX_NAME, COMPLEX_PAYLOAD);
|
let res = req.session().set(COMPLEX_NAME, COMPLEX_PAYLOAD);
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
@ -1033,8 +1015,7 @@ fn test_session_storage_middleware() {
|
|||||||
|
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
})
|
})
|
||||||
})
|
}).resource("/expect_cookie", move |r| {
|
||||||
.resource("/expect_cookie", move |r| {
|
|
||||||
r.f(|req| {
|
r.f(|req| {
|
||||||
let _cookies = req.cookies().expect("To get cookies");
|
let _cookies = req.cookies().expect("To get cookies");
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_start() {
|
fn test_start() {
|
||||||
use std::sync::mpsc;
|
|
||||||
use actix::System;
|
use actix::System;
|
||||||
|
use std::sync::mpsc;
|
||||||
|
|
||||||
let _ = test::TestServer::unused_addr();
|
let _ = test::TestServer::unused_addr();
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
@ -119,9 +119,9 @@ fn test_start() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_shutdown() {
|
fn test_shutdown() {
|
||||||
use std::sync::mpsc;
|
|
||||||
use std::net;
|
|
||||||
use actix::System;
|
use actix::System;
|
||||||
|
use std::net;
|
||||||
|
use std::sync::mpsc;
|
||||||
|
|
||||||
let _ = test::TestServer::unused_addr();
|
let _ = test::TestServer::unused_addr();
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
@ -162,8 +162,8 @@ fn test_shutdown() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn test_panic() {
|
fn test_panic() {
|
||||||
use std::sync::mpsc;
|
|
||||||
use actix::System;
|
use actix::System;
|
||||||
|
use std::sync::mpsc;
|
||||||
|
|
||||||
let _ = test::TestServer::unused_addr();
|
let _ = test::TestServer::unused_addr();
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
@ -176,8 +176,7 @@ fn test_panic() {
|
|||||||
r.method(http::Method::GET).f(|_| -> &'static str {
|
r.method(http::Method::GET).f(|_| -> &'static str {
|
||||||
panic!("error");
|
panic!("error");
|
||||||
});
|
});
|
||||||
})
|
}).resource("/", |r| {
|
||||||
.resource("/", |r| {
|
|
||||||
r.method(http::Method::GET).f(|_| HttpResponse::Ok())
|
r.method(http::Method::GET).f(|_| HttpResponse::Ok())
|
||||||
})
|
})
|
||||||
}).workers(1);
|
}).workers(1);
|
||||||
@ -628,8 +627,7 @@ fn test_gzip_encoding() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Identity)
|
.content_encoding(http::ContentEncoding::Identity)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -661,8 +659,7 @@ fn test_gzip_encoding_large() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Identity)
|
.content_encoding(http::ContentEncoding::Identity)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -698,8 +695,7 @@ fn test_reading_gzip_encoding_large_random() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Identity)
|
.content_encoding(http::ContentEncoding::Identity)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -731,8 +727,7 @@ fn test_reading_deflate_encoding() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Identity)
|
.content_encoding(http::ContentEncoding::Identity)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -764,8 +759,7 @@ fn test_reading_deflate_encoding_large() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Identity)
|
.content_encoding(http::ContentEncoding::Identity)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -801,8 +795,7 @@ fn test_reading_deflate_encoding_large_random() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Identity)
|
.content_encoding(http::ContentEncoding::Identity)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -835,8 +828,7 @@ fn test_brotli_encoding() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Identity)
|
.content_encoding(http::ContentEncoding::Identity)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -869,8 +861,7 @@ fn test_brotli_encoding_large() {
|
|||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_encoding(http::ContentEncoding::Identity)
|
.content_encoding(http::ContentEncoding::Identity)
|
||||||
.body(bytes))
|
.body(bytes))
|
||||||
})
|
}).responder()
|
||||||
.responder()
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -946,14 +937,23 @@ fn test_server_cookies() {
|
|||||||
use actix_web::http;
|
use actix_web::http;
|
||||||
|
|
||||||
let mut srv = test::TestServer::with_factory(|| {
|
let mut srv = test::TestServer::with_factory(|| {
|
||||||
App::new().resource("/", |r| r.f(|_| HttpResponse::Ok().cookie(http::CookieBuilder::new("first", "first_value").http_only(true).finish())
|
App::new().resource("/", |r| {
|
||||||
.cookie(http::Cookie::new("second", "first_value"))
|
r.f(|_| {
|
||||||
|
HttpResponse::Ok()
|
||||||
|
.cookie(
|
||||||
|
http::CookieBuilder::new("first", "first_value")
|
||||||
|
.http_only(true)
|
||||||
|
.finish(),
|
||||||
|
).cookie(http::Cookie::new("second", "first_value"))
|
||||||
.cookie(http::Cookie::new("second", "second_value"))
|
.cookie(http::Cookie::new("second", "second_value"))
|
||||||
.finish())
|
.finish()
|
||||||
)
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let first_cookie = http::CookieBuilder::new("first", "first_value").http_only(true).finish();
|
let first_cookie = http::CookieBuilder::new("first", "first_value")
|
||||||
|
.http_only(true)
|
||||||
|
.finish();
|
||||||
let second_cookie = http::Cookie::new("second", "second_value");
|
let second_cookie = http::Cookie::new("second", "second_value");
|
||||||
|
|
||||||
let request = srv.get().finish().unwrap();
|
let request = srv.get().finish().unwrap();
|
||||||
@ -972,7 +972,9 @@ fn test_server_cookies() {
|
|||||||
let first_cookie = first_cookie.to_string();
|
let first_cookie = first_cookie.to_string();
|
||||||
let second_cookie = second_cookie.to_string();
|
let second_cookie = second_cookie.to_string();
|
||||||
//Check that we have exactly two instances of raw cookie headers
|
//Check that we have exactly two instances of raw cookie headers
|
||||||
let cookies = response.headers().get_all(http::header::SET_COOKIE)
|
let cookies = response
|
||||||
|
.headers()
|
||||||
|
.get_all(http::header::SET_COOKIE)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|header| header.to_str().expect("To str").to_string())
|
.map(|header| header.to_str().expect("To str").to_string())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -103,7 +103,6 @@ fn test_simple_path() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_empty_close_code() {
|
fn test_empty_close_code() {
|
||||||
let mut srv = test::TestServer::new(|app| app.handler(|req| ws::start(req, Ws)));
|
let mut srv = test::TestServer::new(|app| app.handler(|req| ws::start(req, Ws)));
|
||||||
@ -214,8 +213,7 @@ impl Ws2 {
|
|||||||
act.send(ctx);
|
act.send(ctx);
|
||||||
}
|
}
|
||||||
actix::fut::ok(())
|
actix::fut::ok(())
|
||||||
})
|
}).wait(ctx);
|
||||||
.wait(ctx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user