Clean up web utilities

This commit is contained in:
Lucien Greathouse 2018-04-12 22:17:41 -07:00
parent 61fc19e948
commit a5c0cfb12b
2 changed files with 4 additions and 4 deletions

View file

@ -3,7 +3,7 @@ use std::time::Instant;
use rouille;
use project::Project;
use web_util::json;
use web_util::json_response;
/// The set of configuration the web server needs to start.
pub struct WebConfig {
@ -39,7 +39,7 @@ pub fn start(config: WebConfig, project: Project, start_time: Instant) {
elapsed.as_secs() as f64 + elapsed.subsec_nanos() as f64 / 1_000_000_000.0
};
json(ServerInfo {
json_response(ServerInfo {
server_version: env!("CARGO_PKG_VERSION"),
protocol_version: 1,
server_id: &server_id,

View file

@ -6,7 +6,7 @@ use serde_json;
static MAX_BODY_SIZE: usize = 25 * 1024 * 1024; // 25 MiB
pub fn json<T: serde::Serialize>(value: T) -> rouille::Response {
pub fn json_response<T: serde::Serialize>(value: T) -> rouille::Response {
let data = serde_json::to_string(&value).unwrap();
rouille::Response::from_data("application/json", data)
}
@ -15,7 +15,7 @@ pub fn json<T: serde::Serialize>(value: T) -> rouille::Response {
///
/// Doesn't do any actual parsing -- all this method does is verify the content
/// type of the request and read the request's body.
pub fn read_json_text(request: &rouille::Request) -> Option<String> {
fn read_json_text(request: &rouille::Request) -> Option<String> {
// Bail out if the request body isn't marked as JSON
match request.header("Content-Type") {
Some(header) => if !header.starts_with("application/json") {