@@ -5,7 +5,7 @@ use std::ffi::c_void;
5
5
use super :: body:: { hyper_body, hyper_buf} ;
6
6
use super :: error:: hyper_code;
7
7
use super :: task:: { hyper_task_return_type, AsTaskType } ;
8
- use super :: HYPER_ITER_CONTINUE ;
8
+ use super :: { UserDataPointer , HYPER_ITER_CONTINUE } ;
9
9
use crate :: ext:: HeaderCaseMap ;
10
10
use crate :: header:: { HeaderName , HeaderValue } ;
11
11
use crate :: { Body , HeaderMap , Method , Request , Response , Uri } ;
@@ -29,6 +29,13 @@ pub(crate) struct ReasonPhrase(pub(crate) Bytes);
29
29
30
30
pub ( crate ) struct RawHeaders ( pub ( crate ) hyper_buf ) ;
31
31
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
+
32
39
// ===== impl hyper_request =====
33
40
34
41
ffi_fn ! {
@@ -129,6 +136,32 @@ ffi_fn! {
129
136
}
130
137
}
131
138
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
+
132
165
impl hyper_request {
133
166
pub ( super ) fn finalize_request ( & mut self ) {
134
167
if let Some ( headers) = self . 0 . extensions_mut ( ) . remove :: < hyper_headers > ( ) {
@@ -394,6 +427,15 @@ unsafe fn raw_name_value(
394
427
Ok ( ( name, value, orig_name) )
395
428
}
396
429
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
+
397
439
#[ cfg( test) ]
398
440
mod tests {
399
441
use super :: * ;
0 commit comments