mirror of
https://github.com/fafhrd91/actix-web
synced 2025-08-31 08:57:00 +02:00
generalize impl Responder for HttpResponse (#2567)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
committed by
GitHub
parent
49cfabeaf5
commit
2462b6dd5d
@@ -22,7 +22,7 @@ use {
|
||||
cookie::Cookie,
|
||||
};
|
||||
|
||||
use crate::{error::Error, HttpResponseBuilder};
|
||||
use crate::{error::Error, HttpRequest, HttpResponseBuilder, Responder};
|
||||
|
||||
/// An outgoing response.
|
||||
pub struct HttpResponse<B = BoxBody> {
|
||||
@@ -311,6 +311,18 @@ impl Future for HttpResponse<BoxBody> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> Responder for HttpResponse<B>
|
||||
where
|
||||
B: MessageBody + 'static,
|
||||
{
|
||||
type Body = B;
|
||||
|
||||
#[inline]
|
||||
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "cookies")]
|
||||
pub struct CookieIter<'a> {
|
||||
iter: std::slice::Iter<'a, HeaderValue>,
|
||||
@@ -333,9 +345,16 @@ impl<'a> Iterator for CookieIter<'a> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use static_assertions::assert_impl_all;
|
||||
|
||||
use super::*;
|
||||
use crate::http::header::{HeaderValue, COOKIE};
|
||||
|
||||
assert_impl_all!(HttpResponse: Responder);
|
||||
assert_impl_all!(HttpResponse<String>: Responder);
|
||||
assert_impl_all!(HttpResponse<&'static str>: Responder);
|
||||
assert_impl_all!(HttpResponse<crate::body::None>: Responder);
|
||||
|
||||
#[test]
|
||||
fn test_debug() {
|
||||
let resp = HttpResponse::Ok()
|
||||
|
Reference in New Issue
Block a user