From bc1bc43f55b92e7f2f5e2da5ab6a15f2953eb009 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 17 Dec 2019 11:32:19 -0800 Subject: [PATCH] Remove a few unused public pieces from the cookie module --- src/cookie.rs | 82 ++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/src/cookie.rs b/src/cookie.rs index 20f6990fe..bcb1effc8 100644 --- a/src/cookie.rs +++ b/src/cookie.rs @@ -1,58 +1,12 @@ -//! The cookies module contains types for working with request and response cookies. +//! HTTP Cookies use crate::header; -use std::borrow::Cow; use std::fmt; use std::time::SystemTime; -/// Convert a time::Tm time to SystemTime. -fn tm_to_systemtime(tm: time::Tm) -> SystemTime { - let seconds = tm.to_timespec().sec; - let duration = std::time::Duration::from_secs(seconds.abs() as u64); - if seconds > 0 { - SystemTime::UNIX_EPOCH + duration - } else { - SystemTime::UNIX_EPOCH - duration - } -} - -/// Error representing a parse failure of a 'Set-Cookie' header. -pub struct CookieParseError(cookie_crate::ParseError); - -impl<'a> fmt::Debug for CookieParseError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.fmt(f) - } -} - -impl<'a> fmt::Display for CookieParseError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.fmt(f) - } -} - -impl std::error::Error for CookieParseError {} - /// A single HTTP cookie. pub struct Cookie<'a>(cookie_crate::Cookie<'a>); -impl<'a> fmt::Debug for Cookie<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.0.fmt(f) - } -} - -impl Cookie<'static> { - /// Construct a new cookie with the given name and value. - pub fn new(name: N, value: V) -> Self - where - N: Into>, - V: Into>, - { - Cookie(cookie_crate::Cookie::new(name, value)) - } -} - impl<'a> Cookie<'a> { fn parse(value: &'a crate::header::HeaderValue) -> Result, CookieParseError> { std::str::from_utf8(value.as_bytes()) @@ -119,6 +73,12 @@ impl<'a> Cookie<'a> { } } +impl<'a> fmt::Debug for Cookie<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + pub(crate) fn extract_response_cookies<'a>( headers: &'a hyper::HeaderMap, ) -> impl Iterator, CookieParseError>> + 'a { @@ -137,3 +97,31 @@ impl<'a> fmt::Debug for CookieStore { self.0.fmt(f) } } + +/// Convert a time::Tm time to SystemTime. +fn tm_to_systemtime(tm: time::Tm) -> SystemTime { + let seconds = tm.to_timespec().sec; + let duration = std::time::Duration::from_secs(seconds.abs() as u64); + if seconds > 0 { + SystemTime::UNIX_EPOCH + duration + } else { + SystemTime::UNIX_EPOCH - duration + } +} + +/// Error representing a parse failure of a 'Set-Cookie' header. +pub(crate) struct CookieParseError(cookie_crate::ParseError); + +impl<'a> fmt::Debug for CookieParseError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + +impl<'a> fmt::Display for CookieParseError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + self.0.fmt(f) + } +} + +impl std::error::Error for CookieParseError {}