implement relead_timezone flag

This commit is contained in:
Dietmar Maurer 2019-02-01 09:54:56 +01:00
parent 5d63509787
commit 9707fdadd7

View File

@ -27,6 +27,8 @@ use hyper::service::{Service, NewService};
use hyper::rt::{Future, Stream};
use hyper::header;
extern "C" { fn tzset(); }
pub struct RestServer {
pub api_config: Arc<ApiConfig>,
}
@ -135,6 +137,7 @@ fn get_request_parameters_async(
}
fn proxy_protected_request(
info: &'static ApiMethod,
mut parts: Parts,
req_body: Body,
) -> BoxFut
@ -154,6 +157,12 @@ fn proxy_protected_request(
.request(request)
.map_err(|e| Error::from(e));
let resp = if info.reload_timezone {
Either::A(resp.then(|resp| {unsafe { tzset() }; resp }))
} else {
Either::B(resp)
};
return Box::new(resp);
}
@ -183,6 +192,10 @@ fn handle_sync_api_request(
}
};
if info.reload_timezone {
unsafe { tzset() };
}
if delay {
let delayed_response = tokio::timer::Delay::new(delay_unauth_time)
.map_err(|err| http_err!(INTERNAL_SERVER_ERROR, format!("tokio timer delay error: {}", err)))
@ -462,7 +475,7 @@ pub fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> BoxFut {
MethodDefinition::None => {}
MethodDefinition::Simple(api_method) => {
if api_method.protected && env_type == RpcEnvironmentType::PUBLIC {
return proxy_protected_request(parts, body);
return proxy_protected_request(api_method, parts, body);
} else {
return handle_sync_api_request(rpcenv, api_method, formatter, parts, body, uri_param);
}