aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/server.rs b/src/server.rs
index 948a470..95f8325 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -10,25 +10,41 @@ use snafu::{ResultExt, Snafu};
use crate::request;
+/// The HTTP version used by the server.
const HTTP_VERSION: &'static str = "HTTP/1.1";
+/// Wraps server errors.
#[derive(Debug, Snafu)]
pub enum Error {
+ /// I/O write errors during response output.
#[snafu(context(false))]
Write { source: io::Error },
+ /// Error building the request into a [`FastCgiRequest`][FastCgiRequest].
+ ///
+ /// [FastCgiRequest]: ../request/struct.FastCgiRequest.html
#[snafu(display("Couldn't build request: {}", source))]
RequestBuilder { source: request::Error },
+ /// Error building a [`conduit::Response`][conduit::Response].
+ ///
+ /// [conduit::Response]: ../../conduit/struct.Response.html
#[snafu(display("Couldn't parse response: {}", source))]
ConduitResponse { source: conduit::BoxError },
}
+/// The application server that interfaces with FastCGI.
pub struct Server;
impl Server {
+ /// Start the server.
+ ///
+ /// Start the main [`fastcgi::run`][fastcgi::run] process to listen for
+ /// requests and handle them using `handler`.
+ ///
+ /// [fastcgi::run]: ../../fastcgi/fn.run.html
pub fn start<H: Handler + 'static + Sync>(handler: H) -> io::Result<Server> {
fastcgi::run(move |mut raw_request| {
match handle_request(&mut raw_request, &handler) {
@@ -56,6 +72,8 @@ impl Server {
}
}
+/// Given a raw FastCGI request and a Conduit handler, get a response from the
+/// handler to write to a FastCGI response.
fn handle_request<H>(
mut raw_request: &mut fastcgi::Request,
handler: &H,
@@ -100,6 +118,7 @@ where H: Handler + 'static + Sync
Ok(())
}
+/// Write a 500 internal server error to `w`.
fn internal_server_error<W: Write>(mut w: W) {
let code = conduit::StatusCode::INTERNAL_SERVER_ERROR;