1
Fork 0
hare-http/cmd/http/main.ha
2023-02-10 10:13:30 +01:00

32 lines
666 B
Hare

use fmt;
use io;
use net::dial;
use net::http;
use net::uri;
use os;
export fn main() void = {
const client = http::newclient("Hare test client");
defer http::client_finish(&client);
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)!;
};