-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhc.d
44 lines (37 loc) · 1.06 KB
/
hc.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module hc;
import tango.io.Stdout;
import tango.net.InternetAddress;
import tango.net.http.HttpClient;
import tango.net.http.HttpHeaders;
static import tangled.reactor;
import tangled.http;
import tangled.protocol;
import tangled.log;
auto name = "hc";
mixin SimpleLogger!(name);
int main(char[][] argv) {
log.trace("Starting");
tangled.reactor.callLater(0.0, delegate(int x) {log.error(">>> callback");}, 0);
tangled.reactor.callLater(0.0, &_main, argv);
tangled.reactor.run();
return 0;
}
void _main(char[][]argv) {
log.trace("callback");
Stdout("callback2");
if (argv.length > 1) {
auto client = new AHttpClient (HttpClient.Get, argv[1]);
client.open();
scope(exit) { client.close (); }
void sink (void[] content) {
Stdout(cast(char[])content).flush;
}
if (client.isResponseOK) {
auto length = client.getResponseHeaders.getInt (HttpHeader.ContentLength, uint.max);
Stdout(client.getResponseHeaders).newline.flush;
client.read (&sink, length);
}
else
Stderr(client.getResponse).newline;
}
}