|
1 | 1 | use bindings::{
|
2 |
| - ngx_array_t, ngx_http_headers_in_t, ngx_list_part_t, ngx_list_push, ngx_list_t, ngx_palloc, |
3 |
| - ngx_pool_t, ngx_str_t, ngx_table_elt_t, u_char, |
| 2 | + ngx_array_t, ngx_http_headers_in_t, ngx_http_headers_out_t, ngx_list_part_t, ngx_list_push, |
| 3 | + ngx_list_t, ngx_palloc, ngx_pool_t, ngx_str_t, ngx_table_elt_t, u_char, |
4 | 4 | };
|
5 | 5 | use std::convert::{From, TryFrom};
|
6 | 6 | use std::ffi::OsStr;
|
@@ -84,17 +84,36 @@ impl ngx_http_headers_in_t {
|
84 | 84 |
|
85 | 85 | pub fn add(&mut self, pool: *mut ngx_pool_t, key: &str, value: &str) -> Option<()> {
|
86 | 86 | let table: *mut ngx_table_elt_t = unsafe { ngx_list_push(&mut self.headers) as _ };
|
87 |
| - unsafe { table.as_mut() }.map(|table| { |
88 |
| - table.hash = 1; |
89 |
| - table.key.len = key.len() as _; |
90 |
| - table.key.data = str_to_uchar(pool, key); |
91 |
| - table.value.len = value.len() as _; |
92 |
| - table.value.data = str_to_uchar(pool, value); |
93 |
| - table.lowcase_key = str_to_uchar(pool, String::from(key).to_ascii_lowercase().as_str()); |
94 |
| - }) |
| 87 | + add_to_ngx_table(table, pool, key, value) |
95 | 88 | }
|
96 | 89 | }
|
97 | 90 |
|
| 91 | +impl ngx_http_headers_out_t { |
| 92 | + pub fn add(&mut self, pool: *mut ngx_pool_t, key: &str, value: &str) -> Option<()> { |
| 93 | + let table: *mut ngx_table_elt_t = unsafe { ngx_list_push(&mut self.headers) as _ }; |
| 94 | + add_to_ngx_table(table, pool, key, value) |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +fn add_to_ngx_table( |
| 99 | + table: *mut ngx_table_elt_t, |
| 100 | + pool: *mut ngx_pool_t, |
| 101 | + key: &str, |
| 102 | + value: &str, |
| 103 | +) -> Option<()> { |
| 104 | + if table.is_null() { |
| 105 | + return None; |
| 106 | + } |
| 107 | + unsafe { table.as_mut() }.map(|table| { |
| 108 | + table.hash = 1; |
| 109 | + table.key.len = key.len() as _; |
| 110 | + table.key.data = str_to_uchar(pool, key); |
| 111 | + table.value.len = value.len() as _; |
| 112 | + table.value.data = str_to_uchar(pool, value); |
| 113 | + table.lowcase_key = str_to_uchar(pool, String::from(key).to_ascii_lowercase().as_str()); |
| 114 | + }) |
| 115 | +} |
| 116 | + |
98 | 117 | impl IntoIterator for ngx_http_headers_in_t {
|
99 | 118 | type Item = Header;
|
100 | 119 | type IntoIter = ListIterator;
|
|
0 commit comments