summaryrefslogtreecommitdiff
path: root/lib/http
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-03 00:16:54 -0700
committerOri Bernstein <ori@eigenstate.org>2017-09-03 00:16:54 -0700
commitd09137d7087bb2909f1e8ee02a098c44e42958ab (patch)
tree67f47bb3c1e8b8b8c5dfc51db641fb045960e2ea /lib/http
parent0237d07f7d26800a94ddeb25f82a6c7e66ea14c9 (diff)
downloadmc-d09137d7087bb2909f1e8ee02a098c44e42958ab.tar.gz
Update the APIs.
Diffstat (limited to 'lib/http')
-rw-r--r--lib/http/client.myr28
-rw-r--r--lib/http/types.myr18
-rw-r--r--lib/http/url.myr16
3 files changed, 31 insertions, 31 deletions
diff --git a/lib/http/client.myr b/lib/http/client.myr
index d3af84a..ebf0426 100644
--- a/lib/http/client.myr
+++ b/lib/http/client.myr
@@ -7,13 +7,13 @@ use "parse"
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 @@ pkg http =
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
diff --git a/lib/http/types.myr b/lib/http/types.myr
index cb83a57..2b5d2e7 100644
--- a/lib/http/types.myr
+++ b/lib/http/types.myr
@@ -28,15 +28,15 @@ pkg http =
;;
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
diff --git a/lib/http/url.myr b/lib/http/url.myr
index 3d69c4e..be17d20 100644
--- a/lib/http/url.myr
+++ b/lib/http/url.myr
@@ -137,7 +137,7 @@ const parsepath = {url
url# = url#[len:]
-> `std.Ok p
else
- -> `std.Err `Esyntax
+ -> `std.Err `Egarbled
;;
}
@@ -151,13 +151,13 @@ const parseparams = {url
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 @@ const hostname = {url
if ishostchar(chr)
len += std.charlen(chr)
else
- -> `std.Err `Esyntax
+ -> `std.Err `Egarbled
;;
;;
;;
@@ -192,13 +192,13 @@ const ipv6hostname = {url -> std.result(byte[:], err)
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 ipv6hostname = {url -> std.result(byte[:], err)
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)
;;