946c985a02
New patch will implement more transports, such as chunked and gzip.
40 lines
884 B
Hare
40 lines
884 B
Hare
use io;
|
|
use log;
|
|
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 =>
|
|
log::fatal("Invalid URI");
|
|
};
|
|
defer uri::finish(&target);
|
|
|
|
const resp = match (http::get(&client, &target)) {
|
|
case let err: http::error =>
|
|
log::fatal("HTTP error:", http::strerror(err));
|
|
case let resp: http::response =>
|
|
yield resp;
|
|
};
|
|
defer http::response_finish(&resp);
|
|
|
|
log::printfln("HTTP/{}.{}: {} {}",
|
|
resp.version.0, resp.version.1,
|
|
resp.status, resp.reason);
|
|
|
|
for (let i = 0z; i < len(resp.header); i += 1) {
|
|
const (name, val) = resp.header[i];
|
|
log::printfln("{}: {}", name, val);
|
|
};
|
|
|
|
const body = resp.body as *io::stream;
|
|
io::copy(os::stdout, body)!;
|
|
};
|