@@ -5,7 +5,7 @@ use std::ffi::c_void;
55use super :: body:: { hyper_body, hyper_buf} ;
66use super :: error:: hyper_code;
77use super :: task:: { hyper_task_return_type, AsTaskType } ;
8- use super :: HYPER_ITER_CONTINUE ;
8+ use super :: { UserDataPointer , HYPER_ITER_CONTINUE } ;
99use crate :: ext:: HeaderCaseMap ;
1010use crate :: header:: { HeaderName , HeaderValue } ;
1111use crate :: { Body , HeaderMap , Method , Request , Response , Uri } ;
@@ -29,6 +29,13 @@ pub(crate) struct ReasonPhrase(pub(crate) Bytes);
2929
3030pub ( crate ) struct RawHeaders ( pub ( crate ) hyper_buf ) ;
3131
32+ pub ( crate ) struct OnInformational {
33+ func : hyper_request_on_informational_callback ,
34+ data : UserDataPointer ,
35+ }
36+
37+ type hyper_request_on_informational_callback = extern "C" fn ( * mut c_void , * const hyper_response ) ;
38+
3239// ===== impl hyper_request =====
3340
3441ffi_fn ! {
@@ -129,6 +136,32 @@ ffi_fn! {
129136 }
130137}
131138
139+ ffi_fn ! {
140+ /// Set an informational (1xx) response callback.
141+ ///
142+ /// The callback is called each time hyper receives an informational (1xx)
143+ /// response for this request.
144+ ///
145+ /// The third argument is an opaque user data pointer, which is passed to
146+ /// the callback each time.
147+ ///
148+ /// The callback is passed the `void *` data pointer, and a
149+ /// `hyper_response *` which can be inspected as any other response. The
150+ /// body of the response will always be empty.
151+ ///
152+ /// NOTE: The `const hyper_response *` is just borrowed data, and will not
153+ /// be valid after the callback finishes. You must copy any data you wish
154+ /// to persist.
155+ fn hyper_request_on_informational( req: * mut hyper_request, callback: hyper_request_on_informational_callback, data: * mut c_void) -> hyper_code {
156+ let ext = OnInformational {
157+ func: callback,
158+ data: UserDataPointer ( data) ,
159+ } ;
160+ unsafe { & mut * req } . 0 . extensions_mut( ) . insert( ext) ;
161+ hyper_code:: HYPERE_OK
162+ }
163+ }
164+
132165impl hyper_request {
133166 pub ( super ) fn finalize_request ( & mut self ) {
134167 if let Some ( headers) = self . 0 . extensions_mut ( ) . remove :: < hyper_headers > ( ) {
@@ -394,6 +427,15 @@ unsafe fn raw_name_value(
394427 Ok ( ( name, value, orig_name) )
395428}
396429
430+ // ===== impl OnInformational =====
431+
432+ impl OnInformational {
433+ pub ( crate ) fn call ( & mut self , resp : Response < Body > ) {
434+ let mut resp = hyper_response ( resp) ;
435+ ( self . func ) ( self . data . 0 , & mut resp) ;
436+ }
437+ }
438+
397439#[ cfg( test) ]
398440mod tests {
399441 use super :: * ;
0 commit comments