@@ -31,10 +31,11 @@ pub struct Http(HttpProtocol);
3131
3232impl Http {
3333 /// Receive HTTP Protocol configuration.
34- pub fn get_mode_data ( & mut self , config_data : & mut HttpConfigData ) -> uefi:: Result < ( ) > {
35- let status = unsafe { ( self . 0 . get_mode_data ) ( & mut self . 0 , config_data) } ;
34+ pub fn get_mode_data ( & mut self ) -> uefi:: Result < HttpConfigData > {
35+ let mut config_data = HttpConfigData :: default ( ) ;
36+ let status = unsafe { ( self . 0 . get_mode_data ) ( & mut self . 0 , & mut config_data) } ;
3637 match status {
37- Status :: SUCCESS => Ok ( ( ) ) ,
38+ Status :: SUCCESS => Ok ( config_data ) ,
3839 _ => Err ( status. into ( ) ) ,
3940 }
4041 }
@@ -116,18 +117,23 @@ impl HttpBinding {
116117 }
117118}
118119
119- /// HTTP Response data
120+ /// Representation of the underlying UEFI HTTP response.
121+ ///
122+ /// Helper type for [`HttpHelper`].
120123#[ derive( Debug ) ]
121124pub struct HttpHelperResponse {
122125 /// HTTP Status
123126 pub status : HttpStatusCode ,
124127 /// HTTP Response Headers
125128 pub headers : Vec < ( String , String ) > ,
126- /// HTTP Body
129+ /// Partial or entire HTTP body, depending on context.
127130 pub body : Vec < u8 > ,
128131}
129132
130- /// HTTP Helper, makes using the HTTP protocol more convenient.
133+ /// HTTP Helper, makes using the [HTTP] [`Protocol`] more convenient.
134+ ///
135+ /// [HTTP]: Http
136+ /// [`Protocol`]: uefi::proto::Protocol
131137#[ derive( Debug ) ]
132138pub struct HttpHelper {
133139 child_handle : Handle ,
@@ -270,7 +276,12 @@ impl HttpHelper {
270276 Ok ( ( ) )
271277 }
272278
273- /// Receive the start of the http response, the headers and (parts of) the body.
279+ /// Receive the start of the http response, the headers and (parts of) the
280+ /// body.
281+ ///
282+ /// Depending on the HTTP response, its length, its encoding, and its
283+ /// transmission method (chunked or not), users may have to call
284+ /// [`Self::response_more`] afterward.
274285 pub fn response_first ( & mut self , expect_body : bool ) -> uefi:: Result < HttpHelperResponse > {
275286 let mut rx_rsp = HttpResponseData {
276287 status_code : HttpStatusCode :: STATUS_UNSUPPORTED ,
@@ -336,12 +347,13 @@ impl HttpHelper {
336347 Ok ( rsp)
337348 }
338349
339- /// Receive more body data.
340- pub fn response_more ( & mut self ) -> uefi:: Result < Vec < u8 > > {
341- let mut body = vec ! [ 0 ; 16 * 1024 ] ;
350+ /// Try to receive more of the HTTP response and append any new data to the
351+ /// provided `body` vector.
352+ pub fn response_more < ' a > ( & mut self , body : & ' a mut Vec < u8 > ) -> uefi:: Result < & ' a [ u8 ] > {
353+ let mut body_recv_buffer = vec ! [ 0 ; 16 * 1024 ] ;
342354 let mut rx_msg = HttpMessage {
343- body_length : body . len ( ) ,
344- body : body . as_mut_ptr ( ) . cast :: < c_void > ( ) ,
355+ body_length : body_recv_buffer . len ( ) ,
356+ body : body_recv_buffer . as_mut_ptr ( ) . cast :: < c_void > ( ) ,
345357 ..Default :: default ( )
346358 } ;
347359
@@ -367,9 +379,16 @@ impl HttpHelper {
367379 return Err ( rx_token. status . into ( ) ) ;
368380 } ;
369381
370- debug ! ( "http: body: {}/{}" , rx_msg. body_length, body. len( ) ) ;
382+ debug ! (
383+ "http: body: {}/{}" ,
384+ rx_msg. body_length,
385+ body_recv_buffer. len( )
386+ ) ;
371387
372- Ok ( body[ 0 ..rx_msg. body_length ] . to_vec ( ) )
388+ let new_data = & body_recv_buffer[ 0 ..rx_msg. body_length ] ;
389+ body. extend ( new_data) ;
390+ let new_data_slice = & body[ body. len ( ) - new_data. len ( ) ..] ;
391+ Ok ( new_data_slice)
373392 }
374393}
375394
0 commit comments