doc tests for new builder use new builder

This commit is contained in:
Rob Ede 2021-04-08 23:03:56 +01:00
parent ec375cdd71
commit 0f4ab52ebb
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
1 changed files with 24 additions and 39 deletions

View File

@ -234,19 +234,6 @@ impl<B> HttpResponse<B> {
} }
} }
// /// Set a body and return previous body value
// pub(crate) fn replace_body<B2>(self, body: B2) -> (HttpResponse<B2>, ResponseBody<B>) {
// let (res, old_body) = self.res.replace_body(body);
// (
// HttpResponse {
// res,
// error: self.error,
// },
// old_body,
// )
// }
/// Set a body and return previous body value /// Set a body and return previous body value
pub fn map_body<F, B2>(self, f: F) -> HttpResponse<B2> pub fn map_body<F, B2>(self, f: F) -> HttpResponse<B2>
where where
@ -349,11 +336,10 @@ impl HttpResponseBuilder {
/// Insert a header, replacing any that were set with an equivalent field name. /// Insert a header, replacing any that were set with an equivalent field name.
/// ///
/// ``` /// ```
/// # use actix_http::Response; /// use actix_web::{HttpResponse, http::header};
/// use actix_http::http::header;
/// ///
/// Response::Ok() /// HttpResponse::Ok()
/// .insert_header((header::CONTENT_TYPE, mime::APPLICATION_JSON)) /// .insert_header(header::ContentType(mime::APPLICATION_JSON))
/// .insert_header(("X-TEST", "value")) /// .insert_header(("X-TEST", "value"))
/// .finish(); /// .finish();
/// ``` /// ```
@ -376,11 +362,10 @@ impl HttpResponseBuilder {
/// Append a header, keeping any that were set with an equivalent field name. /// Append a header, keeping any that were set with an equivalent field name.
/// ///
/// ``` /// ```
/// # use actix_http::Response; /// use actix_web::{HttpResponse, http::header};
/// use actix_http::http::header;
/// ///
/// Response::Ok() /// HttpResponse::Ok()
/// .append_header((header::CONTENT_TYPE, mime::APPLICATION_JSON)) /// .append_header(header::ContentType(mime::APPLICATION_JSON))
/// .append_header(("X-TEST", "value1")) /// .append_header(("X-TEST", "value1"))
/// .append_header(("X-TEST", "value2")) /// .append_header(("X-TEST", "value2"))
/// .finish(); /// .finish();
@ -514,23 +499,21 @@ impl HttpResponseBuilder {
self self
} }
/// Set a cookie /// Set a cookie.
/// ///
/// ``` /// ```
/// use actix_http::{http, Request, Response}; /// use actix_web::{HttpResponse, cookie::Cookie};
/// ///
/// fn index(req: Request) -> Response { /// HttpResponse::Ok()
/// Response::Ok() /// .cookie(
/// .cookie( /// Cookie::build("name", "value")
/// http::Cookie::build("name", "value") /// .domain("www.rust-lang.org")
/// .domain("www.rust-lang.org") /// .path("/")
/// .path("/") /// .secure(true)
/// .secure(true) /// .http_only(true)
/// .http_only(true) /// .finish(),
/// .finish(), /// )
/// ) /// .finish();
/// .finish()
/// }
/// ``` /// ```
#[cfg(feature = "cookies")] #[cfg(feature = "cookies")]
pub fn cookie<'c>(&mut self, cookie: Cookie<'c>) -> &mut Self { pub fn cookie<'c>(&mut self, cookie: Cookie<'c>) -> &mut Self {
@ -544,13 +527,15 @@ impl HttpResponseBuilder {
self 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 { /// async fn handler(req: HttpRequest) -> impl Responder {
/// let mut builder = Response::Ok(); /// let mut builder = HttpResponse::Ok();
/// ///
/// if let Some(ref cookie) = req.cookie("name") { /// if let Some(ref cookie) = req.cookie("name") {
/// builder.del_cookie(cookie); /// builder.del_cookie(cookie);