Skip to content

Commit

Permalink
Fix response if cookies are not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
george-hopkins committed Jun 18, 2021
1 parent 66fbebf commit 5a5c9ef
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>),
Expand All @@ -20,7 +22,7 @@ pub(crate) enum CookieEvent {
pub struct Response {
pub(crate) res: http::Response,
pub(crate) error: Option<Error>,
// tracking here
#[cfg(feature = "cookies")]
pub(crate) cookie_events: Vec<CookieEvent>,
}

Expand All @@ -36,6 +38,7 @@ impl Response {
Self {
res,
error: None,
#[cfg(feature = "cookies")]
cookie_events: vec![],
}
}
Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand Down Expand Up @@ -432,6 +437,7 @@ impl Response {
Self {
res,
error: None,
#[cfg(feature = "cookies")]
cookie_events: vec![],
}
}
Expand Down Expand Up @@ -488,6 +494,7 @@ impl From<Error> for Response {
Self {
res: http::Response::new(err.status()),
error: Some(err),
#[cfg(feature = "cookies")]
cookie_events: vec![],
}
}
Expand All @@ -498,6 +505,7 @@ impl From<http::Response> for Response {
Self {
res,
error: None,
#[cfg(feature = "cookies")]
cookie_events: vec![],
}
}
Expand Down

0 comments on commit 5a5c9ef

Please sign in to comment.