@@ -13,7 +13,7 @@ use std::{
1313#[ derive( Clone , Debug ) ]
1414pub struct CookieRejectedError {
1515 kind : CookieRejectedErrorKind ,
16- cookie : Cookie ,
16+ cookie : Box < Cookie > ,
1717}
1818
1919/// The reason why the [`Cookie`] was rejected.
@@ -35,14 +35,21 @@ pub enum CookieRejectedErrorKind {
3535}
3636
3737impl CookieRejectedError {
38+ fn new ( kind : CookieRejectedErrorKind , cookie : Cookie ) -> Self {
39+ Self {
40+ kind,
41+ cookie : Box :: new ( cookie) ,
42+ }
43+ }
44+
3845 /// Get the kind of error that occurred.
3946 pub fn kind ( & self ) -> CookieRejectedErrorKind {
4047 self . kind
4148 }
4249
4350 /// Get back the [`Cookie`] that failed to be set.
4451 pub fn cookie ( self ) -> Cookie {
45- self . cookie
52+ * self . cookie
4653 }
4754}
4855
@@ -138,10 +145,10 @@ impl CookieJar {
138145 "cookie '{}' dropped, no domain specified in request URI" ,
139146 cookie. name( )
140147 ) ;
141- return Err ( CookieRejectedError {
142- kind : CookieRejectedErrorKind :: InvalidRequestDomain ,
148+ return Err ( CookieRejectedError :: new (
149+ CookieRejectedErrorKind :: InvalidRequestDomain ,
143150 cookie,
144- } ) ;
151+ ) ) ;
145152 } ;
146153
147154 // Perform some validations on the domain.
@@ -155,10 +162,10 @@ impl CookieJar {
155162 request_host,
156163 domain
157164 ) ;
158- return Err ( CookieRejectedError {
159- kind : CookieRejectedErrorKind :: DomainMismatch ,
165+ return Err ( CookieRejectedError :: new (
166+ CookieRejectedErrorKind :: DomainMismatch ,
160167 cookie,
161- } ) ;
168+ ) ) ;
162169 }
163170
164171 // Drop cookies for top-level domains.
@@ -168,10 +175,10 @@ impl CookieJar {
168175 cookie. name( ) ,
169176 domain
170177 ) ;
171- return Err ( CookieRejectedError {
172- kind : CookieRejectedErrorKind :: InvalidCookieDomain ,
178+ return Err ( CookieRejectedError :: new (
179+ CookieRejectedErrorKind :: InvalidCookieDomain ,
173180 cookie,
174- } ) ;
181+ ) ) ;
175182 }
176183
177184 // Check the PSL for bad domain suffixes if available.
@@ -184,10 +191,10 @@ impl CookieJar {
184191 cookie. name( ) ,
185192 domain
186193 ) ;
187- return Err ( CookieRejectedError {
188- kind : CookieRejectedErrorKind :: InvalidCookieDomain ,
194+ return Err ( CookieRejectedError :: new (
195+ CookieRejectedErrorKind :: InvalidCookieDomain ,
189196 cookie,
190- } ) ;
197+ ) ) ;
191198 }
192199 }
193200 }
0 commit comments