summaryrefslogtreecommitdiff
path: root/lib/http
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-06-19 18:52:08 -0700
committerOri Bernstein <ori@eigenstate.org>2016-06-19 18:58:29 -0700
commit6dcd37d6483c01449c9ded6147b0487feca92744 (patch)
tree8ae7890ad7b45419310eee27d32fc09973edb440 /lib/http
parent22d71e9e0471402b4d9e918f4f10683137ee9121 (diff)
downloadmc-6dcd37d6483c01449c9ded6147b0487feca92744.tar.gz
Fix some typos.
Diffstat (limited to 'lib/http')
-rw-r--r--lib/http/main.myr13
-rw-r--r--lib/http/session.myr12
-rw-r--r--lib/http/url.myr1
-rw-r--r--lib/http/verbs.myr2
4 files changed, 18 insertions, 10 deletions
diff --git a/lib/http/main.myr b/lib/http/main.myr
index e08124d..9ec6566 100644
--- a/lib/http/main.myr
+++ b/lib/http/main.myr
@@ -22,7 +22,7 @@ const main = {args
match opt
| ('m', m): method = m
| ('d', d): data = d
- | ('h', ""): hdr = true
+ | ('H', ""): hdr = true
| _: std.die("unreachable")
;;
;;
@@ -30,15 +30,14 @@ const main = {args
for url in cmd.args
u = std.try(http.parseurl(url))
- std.put("URL: {}\n", u#)
- s = std.try(http.mksession(u.host))
+ s = std.try(http.mksession(u.schema, u.host, u.port))
match method
| "get": r = http.get(s, u.path)
| "head": r = http.head(s, u.path)
| "delete": r = http.delete(s, u.path)
| "trace": r = http.trace(s, u.path)
- | "options": r = http.trace(s, u.path)
+ | "options": r = http.options(s, u.path)
| "put": r = http.put(s, u.path, data)
| "post": r = http.post(s, u.path, data)
| unknown: std.fatal("unknown method '{}'\n", unknown)
@@ -47,8 +46,10 @@ const main = {args
match r
| `std.Ok resp:
std.put("status: {}\n", resp.status)
- for h in resp.hdrs
- std.put("{}\n", h)
+ if hdr
+ for h in resp.hdrs
+ std.put("{}\n", h)
+ ;;
;;
std.put("{}\n", resp.body)
http.freeresp(resp)
diff --git a/lib/http/session.myr b/lib/http/session.myr
index 3b3c1c8..5ceb008 100644
--- a/lib/http/session.myr
+++ b/lib/http/session.myr
@@ -4,17 +4,22 @@ use bio
use "types"
pkg http =
- const mksession : (host : byte[:] -> std.result(session#, err))
+ const mksession : (schema : schema, host : byte[:], port : int -> std.result(session#, err))
const freesession : (s : session# -> void)
pkglocal const ioput : (s : session#, fmt : byte[:], args : ... -> bool)
pkglocal const ioflush : (s : session# -> void)
;;
-const mksession = {host
+const mksession = {schema, host, port
var s, sess
- s = std.fmt("tcp!{}!80", host)
+ match schema
+ | `Http: /* nothing */
+ | `Https: std.fatal("unsupported protocol\n")
+ ;;
+
+ s = std.fmt("tcp!{}!{}", host, port)
match std.dial(s)
| `std.Fail e: sess = `std.Fail `Econn
| `std.Ok fd: sess = `std.Ok std.mk([
@@ -24,6 +29,7 @@ const mksession = {host
.f = bio.mkfile(fd, bio.Rw)
])
;;
+ std.slfree(s)
-> sess
}
diff --git a/lib/http/url.myr b/lib/http/url.myr
index 6f037f8..f311480 100644
--- a/lib/http/url.myr
+++ b/lib/http/url.myr
@@ -35,6 +35,7 @@ const parseurl = {url
-> `std.Ok std.mk([
.schema=schema,
.host=std.sldup(host),
+ .port=port,
.path=std.sldup(path),
])
}
diff --git a/lib/http/verbs.myr b/lib/http/verbs.myr
index 9a3518c..86c5a6b 100644
--- a/lib/http/verbs.myr
+++ b/lib/http/verbs.myr
@@ -72,7 +72,7 @@ const options = {s, path
}
const trace = {s, path
- match request(s, `Options, path, [][:], `std.None)
+ match request(s, `Trace, path, [][:], `std.None)
| `std.Ok _: /* nothing */
| `std.Fail e: -> `std.Fail e
;;