commit - ee4be27b0ba32039999cee9968758d680f9ef341
commit + 0c267caa65186aa3f93b2ec49005d6e7cb239a73
blob - 0797bb1145b1f06bcf8b6208ec0d6047f3d3e192 (mode 644)
blob + /dev/null
--- http/errors.ha
+++ /dev/null
-// This is free and unencumbered software released into the public domain.
-//
-// Anyone is free to copy, modify, publish, use, compile, sell, or
-// distribute this software, either in source code form or as a compiled
-// binary, for any purpose, commercial or non-commercial, and by any
-// means.
-//
-// In jurisdictions that recognize copyright laws, the author or authors
-// of this software dedicate any and all copyright interest in the
-// software to the public domain. We make this dedication for the benefit
-// of the public at large and to the detriment of our heirs and
-// successors. We intend this dedication to be an overt act of
-// relinquishment in perpetuity of all present and future rights to this
-// software under copyright law.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-// OTHER DEALINGS IN THE SOFTWARE.
-
-use io;
-
-export type badrequest = !void;
-export type error = !(io::error | badrequest);
-
-export fn strerror(err: error) str = {
- match (err) {
- case badrequest => return "Bad Request";
- case let err: io::error => return io::strerror(err);
- };
-};
blob - 0cdadf8d28f0ad42d212f58ccd5cbf5e8e9a2e62
blob + 23594b7dd753141b992b762e15e3d96e46f60a8f
--- http/http.ha
+++ http/http.ha
use ev;
+type badrequest = !void;
+
export type version = enum {
HTTP_1_0,
HTTP_1_1,
chunked: bool,
};
-export type routefn = *fn(*request, *reswriter) (void | error);
+export type routefn = *fn(*request, *reswriter) (void | io::error);
type client = struct {
fp: io::file,
ev::add(sock, ev::READ, &handleclt, clt);
};
-fn parse_req(c: *client) (bool | error | encoding::utf8::invalid) = {
+fn parse_req(
+ c: *client
+) (bool | badrequest | io::error | encoding::utf8::invalid) = {
for (true) {
let line = match(bufio::scan_string(&c.in, "\r\n")) {
case io::EOF => return badrequest;
let clt = data: *client;
match (respond(clt)) {
- case let err: error =>
- log::printfln("failure: {}", strerror(err));
+ case let err: io::error =>
+ log::printfln("failure: {}", io::strerror(err));
delclient(clt);
return;
case =>
};
};
-fn handle_request(clt: *client) (void | error) = {
+fn handle_request(clt: *client) (void | io::error) = {
match (parse_req(clt)) {
case let done: bool =>
if (!done)
clt.request_done = true;
};
-fn respond(clt: *client) (void | error) = {
+fn respond(clt: *client) (void | io::error) = {
if (!clt.request_done)
handle_request(clt)?;
if (!clt.request_done)
reswriter_flush(&clt.response)?;
};
-fn route_notfound(req: *request, res: *reswriter) (void | error) = {
+fn route_notfound(req: *request, res: *reswriter) (void | io::error) = {
reply(req, res, 404, "Not Found")?;
header(res, "Content-Type", "text/plain")?;
fmt::fprintln(res, "Page not found.")?;
};
-fn route_badrequest(req: *request, res: *reswriter) (void | error) = {
+fn route_badrequest(req: *request, res: *reswriter) (void | io::error) = {
reply(req, res, 400, "Bad Request")?;
header(res, "Content-Type", "text/plain")?;
fmt::fprintln(res, "Bad Request")?;