1010use super :: HttpStatus ;
1111use super :: { BUFFER_SIZE , VERSION } ;
1212use std:: collections:: { HashMap , VecDeque } ;
13+ use std:: sync:: Arc ;
1314use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1415use std:: sync:: mpsc:: { self , Receiver , SendError , Sender , TryRecvError } ;
15- use std:: sync:: Arc ;
1616use std:: thread;
1717use std:: thread:: JoinHandle ;
1818
@@ -36,14 +36,13 @@ impl BaseResponse {
3636 self . status. to_string( ) ,
3737 headers_text
3838 ) ;
39-
39+
4040 let mut response = Vec :: new ( ) ;
4141 response. extend_from_slice ( response_header. as_bytes ( ) ) ;
4242 response
4343 }
4444}
4545
46-
4746/// Represents a full HTTP response (headers + body).
4847pub struct HttpResponse {
4948 base : BaseResponse ,
@@ -83,13 +82,13 @@ impl HttpResponse {
8382 ) -> Box < Self > {
8483 let mut headers = headers. unwrap_or ( HashMap :: new ( ) ) ;
8584 let content = content. as_ref ( ) ;
86-
85+
8786 headers. insert ( "Content-Length" . to_string ( ) , content. len ( ) . to_string ( ) ) ;
8887 headers. insert (
8988 "Server" . to_string ( ) ,
9089 format ! ( "HTeaPot/{}" , VERSION ) . to_string ( ) ,
9190 ) ;
92-
91+
9392 Box :: new ( HttpResponse {
9493 base : BaseResponse { status, headers } ,
9594 content : content. to_owned ( ) ,
@@ -160,7 +159,7 @@ impl HttpResponseCommon for HttpResponse {
160159 if self . raw . is_none ( ) {
161160 self . raw = Some ( self . to_bytes ( ) ) ;
162161 }
163-
162+
164163 let raw = self . raw . as_ref ( ) . unwrap ( ) ;
165164 let mut raw = raw. chunks ( BUFFER_SIZE ) . skip ( self . index ) ;
166165 let byte_chunk = raw. next ( ) . ok_or ( IterError :: Finished ) ?. to_vec ( ) ;
@@ -193,7 +192,7 @@ impl ChunkSender {
193192 /// Sends a new chunk to the output stream.
194193 ///
195194 /// Prepends the size in hex followed by CRLF, then the chunk, then another CRLF.
196-
195+
197196 // fn new(sender: Sender<Vec<u8>>) -> Self {
198197 // Self(sender)
199198 // }
@@ -232,14 +231,14 @@ impl StreamedResponse {
232231 status : HttpStatus :: OK ,
233232 headers : HashMap :: new ( ) ,
234233 } ;
235-
234+
236235 base. headers
237- . insert ( "Transfer-Encoding" . to_string ( ) , "chunked" . to_string ( ) ) ;
236+ . insert ( "Transfer-Encoding" . to_string ( ) , "chunked" . to_string ( ) ) ;
238237 base. headers . insert (
239238 "Server" . to_string ( ) ,
240239 format ! ( "HTeaPot/{}" , VERSION ) . to_string ( ) ,
241240 ) ;
242-
241+
243242 let _ = tx. send ( base. to_bytes ( ) ) ;
244243 let has_end = Arc :: new ( AtomicBool :: new ( false ) ) ;
245244 let action_clon = action. clone ( ) ;
@@ -270,7 +269,7 @@ impl HttpResponseCommon for StreamedResponse {
270269 fn base ( & mut self ) -> & mut BaseResponse {
271270 & mut self . base
272271 }
273-
272+
274273 fn next ( & mut self ) -> Result < Vec < u8 > , IterError > {
275274 self . peek ( )
276275 }
0 commit comments