Skip to content

Commit

Permalink
add not(test) configure to some structs
Browse files Browse the repository at this point in the history
  • Loading branch information
yaa110 committed Jul 1, 2020
1 parent d128c6e commit 59b2458
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/helpers.rs
@@ -1,7 +1,10 @@
use bindings::{
ngx_http_headers_in_t, ngx_http_request_t, ngx_list_part_t, ngx_list_push, ngx_list_t,
ngx_palloc, ngx_str_t, ngx_table_elt_t, ngx_uint_t, u_char,
ngx_http_headers_in_t, ngx_list_part_t, ngx_list_t,
ngx_str_t, ngx_table_elt_t, ngx_uint_t,
ngx_http_request_t, u_char
};
#[cfg(not(test))]
use bindings::{ngx_list_push, ngx_palloc};
use std::convert::From;
use std::marker::PhantomData;
use std::ptr::copy_nonoverlapping;
Expand Down Expand Up @@ -84,6 +87,7 @@ impl From<*const ngx_table_elt_t> for Header {
}

impl Header {
#[cfg(not(test))]
pub fn new(req: &mut ngx_http_request_t) -> Option<Self> {
let table: *const ngx_table_elt_t =
unsafe { ngx_list_push(&mut req.headers_in.headers) as *const _ };
Expand All @@ -93,6 +97,11 @@ impl Header {
Some(Self(table))
}

#[cfg(test)]
pub fn new(req: &mut ngx_http_request_t) -> Option<Self> {
None
}

pub fn key(&self) -> &str {
unsafe { (*self.0).key.to_str() }
}
Expand All @@ -101,6 +110,7 @@ impl Header {
unsafe { (*self.0).value.to_str() }
}

#[cfg(not(test))]
fn str_to_uchar(req: &ngx_http_request_t, data: &str) -> *mut u_char {
let ptr = unsafe { ngx_palloc(req.pool, data.len() as _) };
unsafe {
Expand All @@ -109,6 +119,12 @@ impl Header {
ptr as *mut _
}

#[cfg(test)]
fn str_to_uchar(req: &ngx_http_request_t, data: &str) -> *mut u_char {
std::ptr::null::<*mut u8>() as *mut _
}

#[cfg(not(test))]
pub fn set(&self, req: &ngx_http_request_t, key: &str, lowercase_key: &str, value: &str) {
unsafe { *self.0 }.hash = 1;
unsafe { *self.0 }.lowcase_key = Self::str_to_uchar(req, lowercase_key);
Expand All @@ -122,6 +138,11 @@ impl Header {
};
}

#[cfg(test)]
pub fn set(&self, req: &ngx_http_request_t, key: &str, lowercase_key: &str, value: &str) {

}

pub fn into_inner(self) -> *const ngx_table_elt_t {
self.0
}
Expand Down

0 comments on commit 59b2458

Please sign in to comment.