mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-31 00:50:20 +02:00
clippy warnings; fmt
This commit is contained in:
@@ -150,10 +150,7 @@ impl HttpResponse {
|
||||
if let Some(reason) = self.get_ref().reason {
|
||||
reason
|
||||
} else {
|
||||
self.get_ref()
|
||||
.status
|
||||
.canonical_reason()
|
||||
.unwrap_or("<unknown status code>")
|
||||
self.get_ref().status.canonical_reason().unwrap_or("<unknown status code>")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,10 +463,7 @@ impl HttpResponseBuilder {
|
||||
jar.add(cookie.into_owned());
|
||||
self.cookies = Some(jar)
|
||||
} else {
|
||||
self.cookies
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.add(cookie.into_owned());
|
||||
self.cookies.as_mut().unwrap().add(cookie.into_owned());
|
||||
}
|
||||
self
|
||||
}
|
||||
@@ -534,9 +528,7 @@ impl HttpResponseBuilder {
|
||||
if let Some(e) = self.err.take() {
|
||||
return Error::from(e).into();
|
||||
}
|
||||
let mut response = self.response
|
||||
.take()
|
||||
.expect("cannot reuse response builder");
|
||||
let mut response = self.response.take().expect("cannot reuse response builder");
|
||||
if let Some(ref jar) = self.cookies {
|
||||
for cookie in jar.delta() {
|
||||
match HeaderValue::from_str(&cookie.to_string()) {
|
||||
@@ -558,9 +550,7 @@ impl HttpResponseBuilder {
|
||||
S: Stream<Item = Bytes, Error = E> + 'static,
|
||||
E: Into<Error>,
|
||||
{
|
||||
self.body(Body::Streaming(Box::new(
|
||||
stream.map_err(|e| e.into()),
|
||||
)))
|
||||
self.body(Body::Streaming(Box::new(stream.map_err(|e| e.into()))))
|
||||
}
|
||||
|
||||
/// Set a json body and generate `HttpResponse`
|
||||
@@ -607,7 +597,7 @@ impl HttpResponseBuilder {
|
||||
#[inline]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(borrowed_box))]
|
||||
fn parts<'a>(
|
||||
parts: &'a mut Option<Box<InnerHttpResponse>>, err: &Option<HttpError>
|
||||
parts: &'a mut Option<Box<InnerHttpResponse>>, err: &Option<HttpError>,
|
||||
) -> Option<&'a mut Box<InnerHttpResponse>> {
|
||||
if err.is_some() {
|
||||
return None;
|
||||
@@ -643,9 +633,7 @@ impl Responder for HttpResponseBuilder {
|
||||
|
||||
impl From<&'static str> for HttpResponse {
|
||||
fn from(val: &'static str) -> Self {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/plain; charset=utf-8")
|
||||
.body(val)
|
||||
HttpResponse::Ok().content_type("text/plain; charset=utf-8").body(val)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -662,9 +650,7 @@ impl Responder for &'static str {
|
||||
|
||||
impl From<&'static [u8]> for HttpResponse {
|
||||
fn from(val: &'static [u8]) -> Self {
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/octet-stream")
|
||||
.body(val)
|
||||
HttpResponse::Ok().content_type("application/octet-stream").body(val)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,9 +667,7 @@ impl Responder for &'static [u8] {
|
||||
|
||||
impl From<String> for HttpResponse {
|
||||
fn from(val: String) -> Self {
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/plain; charset=utf-8")
|
||||
.body(val)
|
||||
HttpResponse::Ok().content_type("text/plain; charset=utf-8").body(val)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,9 +703,7 @@ impl<'a> Responder for &'a String {
|
||||
|
||||
impl From<Bytes> for HttpResponse {
|
||||
fn from(val: Bytes) -> Self {
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/octet-stream")
|
||||
.body(val)
|
||||
HttpResponse::Ok().content_type("application/octet-stream").body(val)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -738,9 +720,7 @@ impl Responder for Bytes {
|
||||
|
||||
impl From<BytesMut> for HttpResponse {
|
||||
fn from(val: BytesMut) -> Self {
|
||||
HttpResponse::Ok()
|
||||
.content_type("application/octet-stream")
|
||||
.body(val)
|
||||
HttpResponse::Ok().content_type("application/octet-stream").body(val)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -772,9 +752,7 @@ impl<'a> From<&'a ClientResponse> for HttpResponseBuilder {
|
||||
impl<'a, S> From<&'a HttpRequest<S>> for HttpResponseBuilder {
|
||||
fn from(req: &'a HttpRequest<S>) -> HttpResponseBuilder {
|
||||
if let Some(router) = req.router() {
|
||||
router
|
||||
.server_settings()
|
||||
.get_response_builder(StatusCode::OK)
|
||||
router.server_settings().get_response_builder(StatusCode::OK)
|
||||
} else {
|
||||
HttpResponse::Ok()
|
||||
}
|
||||
@@ -822,14 +800,12 @@ thread_local!(static POOL: Rc<UnsafeCell<HttpResponsePool>> = HttpResponsePool::
|
||||
|
||||
impl HttpResponsePool {
|
||||
pub fn pool() -> Rc<UnsafeCell<HttpResponsePool>> {
|
||||
Rc::new(UnsafeCell::new(HttpResponsePool(
|
||||
VecDeque::with_capacity(128),
|
||||
)))
|
||||
Rc::new(UnsafeCell::new(HttpResponsePool(VecDeque::with_capacity(128))))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_builder(
|
||||
pool: &Rc<UnsafeCell<HttpResponsePool>>, status: StatusCode
|
||||
pool: &Rc<UnsafeCell<HttpResponsePool>>, status: StatusCode,
|
||||
) -> HttpResponseBuilder {
|
||||
let p = unsafe { &mut *pool.as_ref().get() };
|
||||
if let Some(mut msg) = p.0.pop_front() {
|
||||
@@ -853,7 +829,7 @@ impl HttpResponsePool {
|
||||
|
||||
#[inline]
|
||||
pub fn get_response(
|
||||
pool: &Rc<UnsafeCell<HttpResponsePool>>, status: StatusCode, body: Body
|
||||
pool: &Rc<UnsafeCell<HttpResponsePool>>, status: StatusCode, body: Body,
|
||||
) -> HttpResponse {
|
||||
let p = unsafe { &mut *pool.as_ref().get() };
|
||||
if let Some(mut msg) = p.0.pop_front() {
|
||||
@@ -879,7 +855,7 @@ impl HttpResponsePool {
|
||||
#[inline(always)]
|
||||
#[cfg_attr(feature = "cargo-clippy", allow(boxed_local, inline_always))]
|
||||
fn release(
|
||||
pool: &Rc<UnsafeCell<HttpResponsePool>>, mut inner: Box<InnerHttpResponse>
|
||||
pool: &Rc<UnsafeCell<HttpResponsePool>>, mut inner: Box<InnerHttpResponse>,
|
||||
) {
|
||||
let pool = unsafe { &mut *pool.as_ref().get() };
|
||||
if pool.0.len() < 128 {
|
||||
@@ -975,9 +951,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_force_close() {
|
||||
let resp = HttpResponse::build(StatusCode::OK)
|
||||
.force_close()
|
||||
.finish();
|
||||
let resp = HttpResponse::build(StatusCode::OK).force_close().finish();
|
||||
assert!(!resp.keep_alive().unwrap())
|
||||
}
|
||||
|
||||
@@ -986,10 +960,7 @@ mod tests {
|
||||
let resp = HttpResponse::build(StatusCode::OK)
|
||||
.content_type("text/plain")
|
||||
.body(Body::Empty);
|
||||
assert_eq!(
|
||||
resp.headers().get(CONTENT_TYPE).unwrap(),
|
||||
"text/plain"
|
||||
)
|
||||
assert_eq!(resp.headers().get(CONTENT_TYPE).unwrap(), "text/plain")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1073,10 +1044,7 @@ mod tests {
|
||||
HeaderValue::from_static("application/octet-stream")
|
||||
);
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.body().binary().unwrap(),
|
||||
&Binary::from(b"test".as_ref())
|
||||
);
|
||||
assert_eq!(resp.body().binary().unwrap(), &Binary::from(b"test".as_ref()));
|
||||
|
||||
let resp: HttpResponse = b"test".as_ref().respond_to(req.clone()).ok().unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
@@ -1085,10 +1053,7 @@ mod tests {
|
||||
HeaderValue::from_static("application/octet-stream")
|
||||
);
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.body().binary().unwrap(),
|
||||
&Binary::from(b"test".as_ref())
|
||||
);
|
||||
assert_eq!(resp.body().binary().unwrap(), &Binary::from(b"test".as_ref()));
|
||||
|
||||
let resp: HttpResponse = "test".to_owned().into();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
@@ -1097,26 +1062,16 @@ mod tests {
|
||||
HeaderValue::from_static("text/plain; charset=utf-8")
|
||||
);
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.body().binary().unwrap(),
|
||||
&Binary::from("test".to_owned())
|
||||
);
|
||||
assert_eq!(resp.body().binary().unwrap(), &Binary::from("test".to_owned()));
|
||||
|
||||
let resp: HttpResponse = "test"
|
||||
.to_owned()
|
||||
.respond_to(req.clone())
|
||||
.ok()
|
||||
.unwrap();
|
||||
let resp: HttpResponse = "test".to_owned().respond_to(req.clone()).ok().unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.headers().get(CONTENT_TYPE).unwrap(),
|
||||
HeaderValue::from_static("text/plain; charset=utf-8")
|
||||
);
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.body().binary().unwrap(),
|
||||
&Binary::from("test".to_owned())
|
||||
);
|
||||
assert_eq!(resp.body().binary().unwrap(), &Binary::from("test".to_owned()));
|
||||
|
||||
let resp: HttpResponse = (&"test".to_owned()).into();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
@@ -1125,25 +1080,17 @@ mod tests {
|
||||
HeaderValue::from_static("text/plain; charset=utf-8")
|
||||
);
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.body().binary().unwrap(),
|
||||
&Binary::from(&"test".to_owned())
|
||||
);
|
||||
assert_eq!(resp.body().binary().unwrap(), &Binary::from(&"test".to_owned()));
|
||||
|
||||
let resp: HttpResponse = (&"test".to_owned())
|
||||
.respond_to(req.clone())
|
||||
.ok()
|
||||
.unwrap();
|
||||
let resp: HttpResponse =
|
||||
(&"test".to_owned()).respond_to(req.clone()).ok().unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.headers().get(CONTENT_TYPE).unwrap(),
|
||||
HeaderValue::from_static("text/plain; charset=utf-8")
|
||||
);
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.body().binary().unwrap(),
|
||||
&Binary::from(&"test".to_owned())
|
||||
);
|
||||
assert_eq!(resp.body().binary().unwrap(), &Binary::from(&"test".to_owned()));
|
||||
|
||||
let b = Bytes::from_static(b"test");
|
||||
let resp: HttpResponse = b.into();
|
||||
@@ -1179,10 +1126,7 @@ mod tests {
|
||||
HeaderValue::from_static("application/octet-stream")
|
||||
);
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.body().binary().unwrap(),
|
||||
&Binary::from(BytesMut::from("test"))
|
||||
);
|
||||
assert_eq!(resp.body().binary().unwrap(), &Binary::from(BytesMut::from("test")));
|
||||
|
||||
let b = BytesMut::from("test");
|
||||
let resp: HttpResponse = b.respond_to(req.clone()).ok().unwrap();
|
||||
@@ -1192,10 +1136,7 @@ mod tests {
|
||||
HeaderValue::from_static("application/octet-stream")
|
||||
);
|
||||
assert_eq!(resp.status(), StatusCode::OK);
|
||||
assert_eq!(
|
||||
resp.body().binary().unwrap(),
|
||||
&Binary::from(BytesMut::from("test"))
|
||||
);
|
||||
assert_eq!(resp.body().binary().unwrap(), &Binary::from(BytesMut::from("test")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user