Import http routes from Cloud Hypervisor project

Import vmm/src/api/http.rs from Cloud Hyerpvisor project, commit
345c922cb9a88183e2da9d29230ecb945b0a6452 with following changes:
1) use generic type for handler argument.
2) remove server thread relative code.
3) add unit test cases.
4) refine for better code reuse.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
This commit is contained in:
Liu Jiang
2020-03-23 21:26:13 +08:00
committed by Adrian Catangiu
parent 31bc6268c7
commit ac3bb940ab
3 changed files with 159 additions and 0 deletions

View File

@@ -67,6 +67,21 @@ impl Display for ConnectionError {
}
}
/// Errors pertaining to `HttpRoute`.
#[derive(Debug)]
pub enum RouteError {
/// Handler for http routing path already exists.
HandlerExist(String),
}
impl Display for RouteError {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match self {
RouteError::HandlerExist(p) => write!(f, "handler for {} already exists", p),
}
}
}
/// Errors pertaining to `HttpServer`.
#[derive(Debug)]
pub enum ServerError {