mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-25 04:54:07 +00:00
Clean up web utilities
This commit is contained in:
parent
61fc19e948
commit
a5c0cfb12b
2 changed files with 4 additions and 4 deletions
|
|
@ -3,7 +3,7 @@ use std::time::Instant;
|
||||||
use rouille;
|
use rouille;
|
||||||
|
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use web_util::json;
|
use web_util::json_response;
|
||||||
|
|
||||||
/// The set of configuration the web server needs to start.
|
/// The set of configuration the web server needs to start.
|
||||||
pub struct WebConfig {
|
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
|
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"),
|
server_version: env!("CARGO_PKG_VERSION"),
|
||||||
protocol_version: 1,
|
protocol_version: 1,
|
||||||
server_id: &server_id,
|
server_id: &server_id,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use serde_json;
|
||||||
|
|
||||||
static MAX_BODY_SIZE: usize = 25 * 1024 * 1024; // 25 MiB
|
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();
|
let data = serde_json::to_string(&value).unwrap();
|
||||||
rouille::Response::from_data("application/json", data)
|
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
|
/// Doesn't do any actual parsing -- all this method does is verify the content
|
||||||
/// type of the request and read the request's body.
|
/// 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
|
// Bail out if the request body isn't marked as JSON
|
||||||
match request.header("Content-Type") {
|
match request.header("Content-Type") {
|
||||||
Some(header) => if !header.starts_with("application/json") {
|
Some(header) => if !header.starts_with("application/json") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue