diff options
author | Teddy Wing | 2020-07-04 15:33:59 +0200 |
---|---|---|
committer | Teddy Wing | 2020-07-04 15:33:59 +0200 |
commit | 5a207c6649a67871c209f8e1634efcbcc719bee6 (patch) | |
tree | cb567c4cb08701c56cdc4b70289879f76b218ec2 /src/server.rs | |
parent | 44967e5ae07fc99f56c14dc440cf795851ae117f (diff) | |
download | fastcgi-conduit-5a207c6649a67871c209f8e1634efcbcc719bee6.tar.bz2 |
Add documentation
Write doc comments for functions and types, and include a short example.
Diffstat (limited to 'src/server.rs')
-rw-r--r-- | src/server.rs | 19 |
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; |