1
Fork 0
hare-http/cmd/http/main.ha

32 lines
666 B
Hare
Raw Normal View History

2023-02-10 09:13:30 +00:00
use fmt;
use io;
use net::dial;
2023-02-09 19:54:21 +00:00
use net::http;
use net::uri;
use os;
export fn main() void = {
2023-02-09 22:23:05 +00:00
const client = http::newclient("Hare test client");
defer http::client_finish(&client);
2023-02-10 09:13:30 +00:00
const target = match (uri::parse(os::args[1])) {
case let u: uri::uri =>
yield u;
case uri::invalid =>
fmt::fatal("Invalid URI");
};
defer uri::finish(&target);
const req = http::get(&client, &target);
const resp = match (http::do(&client, &req)) {
case let err: http::error =>
fmt::fatal("HTTP error:", http::strerror(err));
case let resp: http::response =>
yield resp;
};
// XXX TEMP
const body = resp.body as io::handle;
io::copy(os::stdout, body)!;
2023-02-09 19:54:21 +00:00
};