From 5a5c9ef84e41041686feb35070f1ef35247211a7 Mon Sep 17 00:00:00 2001 From: George Hopkins Date: Fri, 18 Jun 2021 07:56:06 +0200 Subject: [PATCH] Fix response if cookies are not enabled --- src/response.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/response.rs b/src/response.rs index 82f1ce95..044b9f22 100644 --- a/src/response.rs +++ b/src/response.rs @@ -4,11 +4,13 @@ use std::ops::Index; use serde::Serialize; +#[cfg(feature = "cookies")] use crate::http::cookies::Cookie; use crate::http::headers::{self, HeaderName, HeaderValues, ToHeaderValues}; use crate::http::{self, Body, Error, Mime, StatusCode}; use crate::ResponseBuilder; +#[cfg(feature = "cookies")] #[derive(Debug)] pub(crate) enum CookieEvent { Added(Cookie<'static>), @@ -20,7 +22,7 @@ pub(crate) enum CookieEvent { pub struct Response { pub(crate) res: http::Response, pub(crate) error: Option, - // tracking here + #[cfg(feature = "cookies")] pub(crate) cookie_events: Vec, } @@ -36,6 +38,7 @@ impl Response { Self { res, error: None, + #[cfg(feature = "cookies")] cookie_events: vec![], } } @@ -335,6 +338,7 @@ impl Response { } /// Insert cookie in the cookie jar. + #[cfg(feature = "cookies")] pub fn insert_cookie(&mut self, cookie: Cookie<'static>) { self.cookie_events.push(CookieEvent::Added(cookie)); } @@ -359,6 +363,7 @@ impl Response { /// [`Request::cookie`](crate::Request::cookie). /// /// [section 5.3 step 11 of RFC 6265]: https://tools.ietf.org/html/rfc6265#section-5.3 + #[cfg(feature = "cookies")] pub fn remove_cookie(&mut self, cookie: Cookie<'static>) { self.cookie_events.push(CookieEvent::Removed(cookie)); } @@ -432,6 +437,7 @@ impl Response { Self { res, error: None, + #[cfg(feature = "cookies")] cookie_events: vec![], } } @@ -488,6 +494,7 @@ impl From for Response { Self { res: http::Response::new(err.status()), error: Some(err), + #[cfg(feature = "cookies")] cookie_events: vec![], } } @@ -498,6 +505,7 @@ impl From for Response { Self { res, error: None, + #[cfg(feature = "cookies")] cookie_events: vec![], } }