From 0f4ab52ebb68862152bd94028e7b212ca26d678d Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Thu, 8 Apr 2021 23:03:56 +0100 Subject: [PATCH] doc tests for new builder use new builder --- src/response.rs | 63 +++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/src/response.rs b/src/response.rs index 37e1528fc..1d017f080 100644 --- a/src/response.rs +++ b/src/response.rs @@ -234,19 +234,6 @@ impl HttpResponse { } } - // /// Set a body and return previous body value - // pub(crate) fn replace_body(self, body: B2) -> (HttpResponse, ResponseBody) { - // let (res, old_body) = self.res.replace_body(body); - - // ( - // HttpResponse { - // res, - // error: self.error, - // }, - // old_body, - // ) - // } - /// Set a body and return previous body value pub fn map_body(self, f: F) -> HttpResponse where @@ -349,11 +336,10 @@ impl HttpResponseBuilder { /// Insert a header, replacing any that were set with an equivalent field name. /// /// ``` - /// # use actix_http::Response; - /// use actix_http::http::header; + /// use actix_web::{HttpResponse, http::header}; /// - /// Response::Ok() - /// .insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON)) + /// HttpResponse::Ok() + /// .insert_header(header::ContentType(mime::APPLICATION_JSON)) /// .insert_header(("X-TEST", "value")) /// .finish(); /// ``` @@ -376,11 +362,10 @@ impl HttpResponseBuilder { /// Append a header, keeping any that were set with an equivalent field name. /// /// ``` - /// # use actix_http::Response; - /// use actix_http::http::header; + /// use actix_web::{HttpResponse, http::header}; /// - /// Response::Ok() - /// .append_header((header::CONTENT_TYPE, mime::APPLICATION_JSON)) + /// HttpResponse::Ok() + /// .append_header(header::ContentType(mime::APPLICATION_JSON)) /// .append_header(("X-TEST", "value1")) /// .append_header(("X-TEST", "value2")) /// .finish(); @@ -514,23 +499,21 @@ impl HttpResponseBuilder { self } - /// Set a cookie + /// Set a cookie. /// /// ``` - /// use actix_http::{http, Request, Response}; + /// use actix_web::{HttpResponse, cookie::Cookie}; /// - /// fn index(req: Request) -> Response { - /// Response::Ok() - /// .cookie( - /// http::Cookie::build("name", "value") - /// .domain("www.rust-lang.org") - /// .path("/") - /// .secure(true) - /// .http_only(true) - /// .finish(), - /// ) - /// .finish() - /// } + /// HttpResponse::Ok() + /// .cookie( + /// Cookie::build("name", "value") + /// .domain("www.rust-lang.org") + /// .path("/") + /// .secure(true) + /// .http_only(true) + /// .finish(), + /// ) + /// .finish(); /// ``` #[cfg(feature = "cookies")] pub fn cookie<'c>(&mut self, cookie: Cookie<'c>) -> &mut Self { @@ -544,13 +527,15 @@ impl HttpResponseBuilder { self } - /// Remove cookie + /// Remove cookie. + /// + /// A `Set-Cookie` header is added that will delete a cookie with the same name from the client. /// /// ``` - /// use actix_http::{http, Request, Response, HttpMessage}; + /// use actix_web::{HttpRequest, HttpResponse, Responder}; /// - /// fn index(req: Request) -> Response { - /// let mut builder = Response::Ok(); + /// async fn handler(req: HttpRequest) -> impl Responder { + /// let mut builder = HttpResponse::Ok(); /// /// if let Some(ref cookie) = req.cookie("name") { /// builder.del_cookie(cookie);