diff --git a/cmd/http/main.ha b/cmd/http/main.ha index 72d8901..7d2fe78 100644 --- a/cmd/http/main.ha +++ b/cmd/http/main.ha @@ -1,15 +1,35 @@ +use getopt; use io; use log; use net::dial; use net::http; use net::uri; use os; +use strings; export fn main() void = { const client = http::newclient("Hare net::http test client"); defer http::client_finish(&client); - const target = match (uri::parse(os::args[1])) { + const cmd = getopt::parse(os::args, + "HTTP client", + ('H', "Name:value", "Sets an HTTP header"), + "url"); + defer getopt::finish(&cmd); + + let head = http::client_default_header(&client); + for (let i = 0z; i < len(cmd.opts); i += 1) { + const (opt, val) = cmd.opts[i]; + switch (opt) { + case 'H' => + const (name, val) = strings::cut(val, ":"); + http::header_add(head, name, val); + case => abort(); + }; + }; + + const target = cmd.args[0]; + const target = match (uri::parse(target)) { case let u: uri::uri => yield u; case uri::invalid =>