Unverified Commit e8fa8b5d authored by Alexandru Vasile's avatar Alexandru Vasile
Browse files

http: Transform builder into service directly


Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>
parent 5af12824
......@@ -96,7 +96,7 @@ async fn run_server() -> anyhow::Result<SocketAddr> {
module.register_method("say_hello", |_, _| Ok("lo")).unwrap();
println!("[run_server]: Creating RPC service");
let rpc_svc = HttpServerBuilder::new().set_middleware(Timings).pre_build().to_service(module).unwrap();
let rpc_svc = HttpServerBuilder::new().set_middleware(Timings).to_service(module).unwrap();
println!("[run_server]: Tower builder");
let tower_svc = tower::ServiceBuilder::new()
......
......@@ -345,21 +345,24 @@ impl<M> Builder<M> {
})
}
/// Pre-build the server as is.
pub fn pre_build(self) -> Server<M> {
Server {
listener: None,
local_addr: None,
access_control: self.access_control,
max_request_body_size: self.max_request_body_size,
max_response_body_size: self.max_response_body_size,
batch_requests_supported: self.batch_requests_supported,
resources: self.resources,
tokio_runtime: self.tokio_runtime,
middleware: self.middleware,
max_log_length: self.max_log_length,
health_api: self.health_api,
}
/// Returns a service that can be utilised with `tower` compatible crates.
pub fn to_service(self, methods: impl Into<Methods>) -> Result<RPSeeServerSvc<M>, Error> {
let methods = methods.into().initialize_resources(&self.resources)?;
Ok(RPSeeServerSvc {
inner: RPSeeSvcData {
remote_addr: None,
methods,
acl: self.access_control,
resources: self.resources,
middleware: self.middleware,
health_api: self.health_api,
max_request_body_size: self.max_response_body_size,
max_response_body_size: self.max_response_body_size,
max_log_length: self.max_log_length,
batch_requests_supported: self.batch_requests_supported,
},
})
}
}
......@@ -605,26 +608,6 @@ impl<M: Middleware> Server<M> {
self.local_addr.ok_or_else(|| Error::Custom("Local address not found".into()))
}
/// Returns a service that can be utilised with `tower` compatible crates.
pub fn to_service(self, methods: impl Into<Methods>) -> Result<RPSeeServerSvc<M>, Error> {
let methods = methods.into().initialize_resources(&self.resources)?;
Ok(RPSeeServerSvc {
inner: RPSeeSvcData {
remote_addr: None,
methods,
acl: self.access_control,
resources: self.resources,
middleware: self.middleware,
health_api: self.health_api,
max_request_body_size: self.max_response_body_size,
max_response_body_size: self.max_response_body_size,
max_log_length: self.max_log_length,
batch_requests_supported: self.batch_requests_supported,
},
})
}
/// Start the server.
pub fn start(mut self, methods: impl Into<Methods>) -> Result<ServerHandle, Error> {
let max_request_body_size = self.max_request_body_size;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment