diff --git a/examples/server.rs b/examples/server.rs index 8ac452b..8bbb73c 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -271,7 +271,8 @@ fn start_zlm_background( let uri = format!("http://127.0.0.1:{}{}", AXUM_PORT, path_query); let headers = msg.parser.headers(); - + println!("uri: {}", uri); + println!("headers: {:?}", headers); if let Ok(mut req) = hyper::Request::builder() .method(msg.parser.method().as_str()) .uri(uri) diff --git a/src/obj.rs b/src/obj.rs index 06d93a2..49d6d2b 100644 --- a/src/obj.rs +++ b/src/obj.rs @@ -311,9 +311,11 @@ impl Parser { pub fn headers(&self) -> HashMap { let headers = std::rc::Rc::new(RefCell::new(HashMap::new())); - let headers_clone = headers.clone(); - self.headers_for_each(Box::new(move |key, val| { - headers_clone.borrow_mut().insert(key, val); + self.headers_for_each(Box::new({ + let headers_clone = headers.clone(); + move |key, val| { + headers_clone.borrow_mut().insert(key, val); + } })); let tmp = headers.as_ref().borrow().to_owned(); @@ -331,14 +333,14 @@ impl Parser { } } -type ParserHeadersForEachCallbackFn = Box; +type ParserHeadersForEachCallbackFn = Box; extern "C" fn parser_headers_for_each( user_data: *mut ::std::os::raw::c_void, key: *const ::std::os::raw::c_char, val: *const ::std::os::raw::c_char, ) { unsafe { - let cb: &mut ParserHeadersForEachCallbackFn = std::mem::transmute(user_data); + let cb: &ParserHeadersForEachCallbackFn = std::mem::transmute(user_data); let key = const_ptr_to_string!(key); let val = const_ptr_to_string!(val); cb(key, val);