|
|
@ -61,24 +61,18 @@ where |
|
|
|
let addr = matches.value_of("bind").unwrap().to_owned(); |
|
|
|
let addr = matches.value_of("bind").unwrap().to_owned(); |
|
|
|
println!("Listening for requests at http://{}", &addr); |
|
|
|
println!("Listening for requests at http://{}", &addr); |
|
|
|
|
|
|
|
|
|
|
|
start_server(addr.to_string(), move |request| { |
|
|
|
start_server(addr, move |request| { |
|
|
|
content_encoding::apply( |
|
|
|
content_encoding::apply( |
|
|
|
request, |
|
|
|
request, |
|
|
|
handle_request(request, repository.connection().unwrap(), &addr), |
|
|
|
handle_request(request, repository.connection().unwrap()), |
|
|
|
) |
|
|
|
) |
|
|
|
.with_unique_header("Server", SERVER) |
|
|
|
.with_unique_header("Server", SERVER) |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn handle_request<R: RepositoryConnection>( |
|
|
|
fn handle_request<R: RepositoryConnection>(request: &Request, mut connection: R) -> Response { |
|
|
|
request: &Request, |
|
|
|
|
|
|
|
mut connection: R, |
|
|
|
|
|
|
|
host: &str, |
|
|
|
|
|
|
|
) -> Response { |
|
|
|
|
|
|
|
match (request.url().as_str(), request.method()) { |
|
|
|
match (request.url().as_str(), request.method()) { |
|
|
|
("/", "GET") => { |
|
|
|
("/", "GET") => Response::html(HTML_ROOT_PAGE), |
|
|
|
Response::html(HTML_ROOT_PAGE.replace("{{endpoint}}", &format!("//{}/query", host))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
("/", "POST") => { |
|
|
|
("/", "POST") => { |
|
|
|
if let Some(body) = request.data() { |
|
|
|
if let Some(body) = request.data() { |
|
|
|
if let Some(content_type) = request.header("Content-Type") { |
|
|
|
if let Some(content_type) = request.header("Content-Type") { |
|
|
@ -260,11 +254,7 @@ mod tests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn exec(request: Request) { |
|
|
|
fn exec(request: Request) { |
|
|
|
let response = handle_request( |
|
|
|
let response = handle_request(&request, MemoryRepository::default().connection().unwrap()); |
|
|
|
&request, |
|
|
|
|
|
|
|
MemoryRepository::default().connection().unwrap(), |
|
|
|
|
|
|
|
"localhost", |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
let mut body = String::default(); |
|
|
|
let mut body = String::default(); |
|
|
|
request |
|
|
|
request |
|
|
|
.data() |
|
|
|
.data() |
|
|
|