Commit Diff


commit - ee4be27b0ba32039999cee9968758d680f9ef341
commit + 0c267caa65186aa3f93b2ec49005d6e7cb239a73
blob - 0797bb1145b1f06bcf8b6208ec0d6047f3d3e192 (mode 644)
blob + /dev/null
--- http/errors.ha
+++ /dev/null
@@ -1,34 +0,0 @@
-// 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
@@ -35,6 +35,8 @@ use strings;
 
 use ev;
 
+type badrequest = !void;
+
 export type version = enum {
 	HTTP_1_0,
 	HTTP_1_1,
@@ -61,7 +63,7 @@ export type request = struct {
 	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,
@@ -121,7 +123,9 @@ fn acceptclt(f: io::file, ev: ev::event, data: nullabl
 	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;
@@ -190,8 +194,8 @@ fn handleclt(f: io::file, ev: ev::event, data: nullabl
 	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 =>
@@ -205,7 +209,7 @@ fn handleclt(f: io::file, ev: ev::event, data: nullabl
 	};
 };
 
-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)
@@ -235,7 +239,7 @@ fn handle_request(clt: *client) (void | error) = {
 	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)
@@ -249,13 +253,13 @@ fn respond(clt: *client) (void | error) = {
 	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")?;