ref: 6dcd37d6483c01449c9ded6147b0487feca92744
parent: 22d71e9e0471402b4d9e918f4f10683137ee9121
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jun 19 14:52:08 EDT 2016
Fix some typos.
--- a/lib/http/main.myr
+++ b/lib/http/main.myr
@@ -22,7 +22,7 @@
match opt
| ('m', m): method = m
| ('d', d): data = d
- | ('h', ""): hdr = true
+ | ('H', ""): hdr = true
| _: std.die("unreachable")
;;
;;
@@ -30,8 +30,7 @@
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)
@@ -38,7 +37,7 @@
| "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 @@
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)
--- a/lib/http/session.myr
+++ b/lib/http/session.myr
@@ -4,7 +4,7 @@
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)
@@ -11,10 +11,15 @@
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 @@
.f = bio.mkfile(fd, bio.Rw)
])
;;
+ std.slfree(s)
-> sess
}
--- a/lib/http/url.myr
+++ b/lib/http/url.myr
@@ -35,6 +35,7 @@
-> `std.Ok std.mk([
.schema=schema,
.host=std.sldup(host),
+ .port=port,
.path=std.sldup(path),
])
}
--- a/lib/http/verbs.myr
+++ b/lib/http/verbs.myr
@@ -72,7 +72,7 @@
}
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
;;