shithub: mc

Download patch

ref: d09137d7087bb2909f1e8ee02a098c44e42958ab
parent: 0237d07f7d26800a94ddeb25f82a6c7e66ea14c9
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Sep 2 20:16:54 EDT 2017

Update the APIs.

--- a/lib/http/client.myr
+++ b/lib/http/client.myr
@@ -7,13 +7,13 @@
 
 pkg http =
 	/* simple versions */
-	const get	: (s : session#, r : byte[:] -> std.result(resp#, err))
-	const head	: (s : session#, r : byte[:] -> std.result(resp#, err))
-	const put	: (s : session#, r : byte[:], data : byte[:] -> std.result(resp#, err))
-	const post	: (s : session#, r : byte[:], data : byte[:] -> std.result(resp#, err))
-	const delete	: (s : session#, r : byte[:] -> std.result(resp#, err))
-	const options	: (s : session#, r : byte[:] -> std.result(resp#, err))
-	const trace	: (s : session#, r : byte[:] -> std.result(resp#, err))
+	const get	: (s : session#, r : url# -> std.result(resp#, err))
+	const head	: (s : session#, r : url# -> std.result(resp#, err))
+	const put	: (s : session#, r : url#, data : byte[:] -> std.result(resp#, err))
+	const post	: (s : session#, r : url#, data : byte[:] -> std.result(resp#, err))
+	const delete	: (s : session#, r : url# -> std.result(resp#, err))
+	const options	: (s : session#, r : url# -> std.result(resp#, err))
+	const trace	: (s : session#, r : url# -> std.result(resp#, err))
 
 	/* request based versions */
 	const getreq	: (s : session#, r : req# -> std.result(resp#, err))
@@ -27,13 +27,13 @@
 	const freeresp	: (r : resp# -> void)
 ;;
 
-const get = {s, path; -> getreq(s, &[.url=&[.path=path]])}
-const head = {s, path; -> headreq(s, &[.url=&[.path=path]])}
-const put = {s, path, data; -> putreq(s, &[.url=&[.path=path]], data)}
-const post = {s, path, data; -> postreq(s, &[.url=&[.path=path]], data)}
-const delete = {s, path; -> deletereq(s, &[.url=&[.path=path]])}
-const options = {s, path; -> optionsreq(s, &[.url=&[.path=path]])}
-const trace = {s, path; -> tracereq(s, &[.url=&[.path=path]])}
+const get = {s, path; -> getreq(s, &[.url=path])}
+const head = {s, path; -> headreq(s, &[.url=path])}
+const put = {s, path, data; -> putreq(s, &[.url=path], data)}
+const post = {s, path, data; -> postreq(s, &[.url=path], data)}
+const delete = {s, path; -> deletereq(s, &[.url=path])}
+const options = {s, path; -> optionsreq(s, &[.url=path])}
+const trace = {s, path; -> tracereq(s, &[.url=path])}
 
 
 const getreq = {s, r
--- a/lib/http/types.myr
+++ b/lib/http/types.myr
@@ -28,15 +28,15 @@
 	;;
 
 	type err = union
-		`Ewat
-		`Eunsupp
-		`Econn
-		`Ehttp int
-		`Ehdr
-		`Eproto
-		`Eshort
-		`Esyntax
-		`Eenc
+		`Ehttp int	/* http error */
+		`Eunsupp	/* unsupported feature */
+		`Econn		/* connection lost */
+		`Ehdr		/* invalid header */
+		`Eproto		/* protocol error */
+		`Eshort		/* truncated response */
+		`Egarbled	/* syntax error */
+		`Eenc		/* encoding error */
+		`Ewat		/* unknown error */
 	;;
 
 	type schema = union
--- a/lib/http/url.myr
+++ b/lib/http/url.myr
@@ -137,7 +137,7 @@
 		url# = url#[len:]
 		-> `std.Ok p
 	else
-		-> `std.Err `Esyntax
+		-> `std.Err `Egarbled
 	;;
 }
 
@@ -151,13 +151,13 @@
 
 	match std.decode(url#)
 	| '?':	(_, url#) = std.strstep(url#)
-	| _:	-> `std.Err `Esyntax
+	| _:	-> `std.Err `Egarbled
 	;;
 
 	params = [][:]
 	for sp : std.bysplit(url#, "&")
 		if std.bstrsplit(kvp[:], sp, "=").len != 2
-			-> `std.Err `Esyntax
+			-> `std.Err `Egarbled
 		;;
 		std.slpush(&params, (std.sldup(kvp[0]), std.sldup(kvp[1])))
 	;;
@@ -178,7 +178,7 @@
 			if ishostchar(chr)
 				len += std.charlen(chr)
 			else
-				-> `std.Err `Esyntax
+				-> `std.Err `Egarbled
 			;;
 		;;
 	;;
@@ -192,13 +192,13 @@
 	var ip
 
 	match std.strfind(url#, "]")
-	| `std.None:	-> `std.Err `Esyntax
+	| `std.None:	-> `std.Err `Egarbled
 	| `std.Some idx:
 		ip = url#[:idx]
 		url# = url#[idx+1:]
 		match std.ip6parse(url#[:idx])
 		| `std.Some _:	-> `std.Ok ip
-		| `std.None:	-> `std.Err `Esyntax
+		| `std.None:	-> `std.Err `Egarbled
 		;;
 	;;
 }
@@ -206,10 +206,10 @@
 const parseport = {url
 	if std.chomp(url, ":")
 		match parsenumber(url, 10)
-		| `std.None:	-> `std.Err `Esyntax
+		| `std.None:	-> `std.Err `Egarbled
 		| `std.Some n:
 			if n > 65535
-				-> `std.Err `Esyntax
+				-> `std.Err `Egarbled
 			else
 				-> `std.Ok (n : uint16)
 			;;