@@ -18,10 +18,10 @@ use crate::{
18
18
bindings:: {
19
19
ngx_alloc_chain_link, ngx_buf_t, ngx_chain_s, ngx_hash_find, ngx_hash_key,
20
20
ngx_http_core_main_conf_t, ngx_http_core_module, ngx_http_core_run_phases,
21
- ngx_http_get_indexed_variable, ngx_http_headers_out_t , ngx_http_output_filter ,
22
- ngx_http_parse_multi_header_lines , ngx_http_request_t , ngx_http_send_header ,
23
- ngx_http_variable_t , ngx_list_push , ngx_list_t , ngx_module_t , ngx_pcalloc ,
24
- ngx_posted_events, ngx_table_elt_t,
21
+ ngx_http_get_indexed_variable, ngx_http_headers_in_t , ngx_http_headers_out_t ,
22
+ ngx_http_output_filter , ngx_http_parse_multi_header_lines , ngx_http_request_t ,
23
+ ngx_http_send_header , ngx_http_variable_t , ngx_list_part_t , ngx_list_push , ngx_list_t ,
24
+ ngx_module_t , ngx_pcalloc , ngx_posted_events, ngx_table_elt_t,
25
25
} ,
26
26
connection:: Connection ,
27
27
ngx_post_event, ngx_str_t,
@@ -39,6 +39,13 @@ pub struct HttpRequestAndContext<'a, Ctx>(ngx_http_request_t, PhantomData<&'a Ct
39
39
40
40
pub struct HttpRequest < ' a > ( ngx_http_request_t , PhantomData < & ' a ( ) > ) ;
41
41
42
+ pub struct HeadersIn < ' a > ( ngx_http_headers_in_t , PhantomData < & ' a ( ) > ) ;
43
+ pub struct HeadersInIter < ' a > {
44
+ part : * const ngx_list_part_t ,
45
+ elt_idx : usize ,
46
+ _phantom : PhantomData < & ' a ( ) > ,
47
+ }
48
+
42
49
impl < ' a , Ctx : Default > HttpRequestAndContext < ' a , Ctx > {
43
50
///
44
51
/// # Safety
@@ -250,6 +257,10 @@ impl<'a> HttpRequest<'a> {
250
257
& mut self . 0 . headers_out
251
258
}
252
259
260
+ pub fn headers_in ( & self ) -> & HeadersIn < ' a > {
261
+ unsafe { & * ( & self . 0 . headers_in as * const ngx_http_headers_in_t as * const HeadersIn ) }
262
+ }
263
+
253
264
// TODO:esavier its not named uri but it returns only path
254
265
// TODO:consider either helper or change results to Strings
255
266
pub fn unparsed_uri ( & self ) -> NgxStr {
@@ -511,3 +522,44 @@ impl<'a> HttpRequest<'a> {
511
522
( & self . 0 as * const ngx_http_request_t ) . cast_mut ( )
512
523
}
513
524
}
525
+
526
+ impl < ' a > HeadersIn < ' a > {
527
+ pub fn iter ( & self ) -> HeadersInIter < ' a > {
528
+ HeadersInIter {
529
+ part : & self . 0 . headers . part ,
530
+ elt_idx : 0 ,
531
+ _phantom : PhantomData ,
532
+ }
533
+ }
534
+ }
535
+
536
+ impl < ' a > Iterator for HeadersInIter < ' a > {
537
+ type Item = ( NgxStr < ' a > , NgxStr < ' a > ) ;
538
+
539
+ fn next ( & mut self ) -> Option < Self :: Item > {
540
+ if self . part . is_null ( ) {
541
+ None
542
+ } else {
543
+ unsafe {
544
+ let len = ( * self . part ) . nelts ;
545
+ if self . elt_idx >= len {
546
+ return None ;
547
+ }
548
+ let elem_base = ( * self . part ) . elts as * const ngx_table_elt_t ;
549
+ let elem = elem_base. add ( self . elt_idx ) ;
550
+ let result = (
551
+ NgxStr :: from_raw ( ( * elem) . key ) ,
552
+ NgxStr :: from_raw ( ( * elem) . value ) ,
553
+ ) ;
554
+
555
+ self . elt_idx += 1 ;
556
+ if self . elt_idx >= len {
557
+ self . elt_idx = 0 ;
558
+ self . part = ( * self . part ) . next ;
559
+ }
560
+
561
+ Some ( result)
562
+ }
563
+ }
564
+ }
565
+ }
0 commit comments