@@ -32,8 +32,8 @@ type Result<T> = core::result::Result<T, Box<dyn std::error::Error>>;
3232/// ```
3333///
3434pub struct Response {
35- pub head : ResponseParts ,
36- pub body : Vec < u8 > ,
35+ head : ResponseParts ,
36+ body : Vec < u8 > ,
3737}
3838
3939/// Component parts of an HTTP `Response`
@@ -42,16 +42,16 @@ pub struct Response {
4242/// header fields.
4343#[ derive( Clone ) ]
4444pub struct ResponseParts {
45- /// The response's status
45+ /// The response's status.
4646 pub status : StatusCode ,
4747
48- /// The response's version
48+ /// The response's version.
4949 pub version : Version ,
5050
51- /// The response's headers
51+ /// The response's headers.
5252 pub headers : HeaderMap < HeaderValue > ,
5353
54- /// The response's mimetype type
54+ /// The response's mimetype type.
5555 pub mimetype : Option < String > ,
5656}
5757
@@ -74,16 +74,39 @@ impl Response {
7474 }
7575 }
7676
77- /// Returns the `StatusCode`.
77+ /// Consumes the response returning the head and body ResponseParts.
78+ ///
79+ /// # Stability
80+ ///
81+ /// This API is used internally. It may have breaking changes in the future.
82+ #[ inline]
83+ #[ doc( hidden) ]
84+ pub fn into_parts ( self ) -> ( ResponseParts , Vec < u8 > ) {
85+ ( self . head , self . body )
86+ }
87+
88+ /// Sets the status code.
89+ #[ inline]
90+ pub fn set_status ( & mut self , status : StatusCode ) {
91+ self . head . status = status;
92+ }
93+
94+ /// Returns the [`StatusCode`].
7895 #[ inline]
7996 pub fn status ( & self ) -> StatusCode {
8097 self . head . status
8198 }
8299
100+ /// Sets the mimetype.
101+ #[ inline]
102+ pub fn set_mimetype ( & mut self , mimetype : Option < String > ) {
103+ self . head . mimetype = mimetype;
104+ }
105+
83106 /// Returns a reference to the mime type.
84107 #[ inline]
85- pub fn mimetype ( & self ) -> Option < String > {
86- self . head . mimetype . clone ( )
108+ pub fn mimetype ( & self ) -> Option < & String > {
109+ self . head . mimetype . as_ref ( )
87110 }
88111
89112 /// Returns a reference to the associated version.
@@ -92,12 +115,24 @@ impl Response {
92115 self . head . version
93116 }
94117
118+ /// Returns a mutable reference to the associated header field map.
119+ #[ inline]
120+ pub fn headers_mut ( & mut self ) -> & mut HeaderMap < HeaderValue > {
121+ & mut self . head . headers
122+ }
123+
95124 /// Returns a reference to the associated header field map.
96125 #[ inline]
97126 pub fn headers ( & self ) -> & HeaderMap < HeaderValue > {
98127 & self . head . headers
99128 }
100129
130+ /// Returns a mutable reference to the associated HTTP body.
131+ #[ inline]
132+ pub fn body_mut ( & mut self ) -> & mut Vec < u8 > {
133+ & mut self . body
134+ }
135+
101136 /// Returns a reference to the associated HTTP body.
102137 #[ inline]
103138 pub fn body ( & self ) -> & Vec < u8 > {
0 commit comments