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
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vbench/http/http_result_handler.h>
#include <vbench/http/server_spec.h>
#include <vbench/http/http_client.h>
#include <vespa/fastos/app.h>
using namespace vbench;
class App : public FastOS_Application
{
public:
int Main() override;
};
struct MyHttpHandler : public HttpResultHandler {
void handleHeader(const string &name, const string &value) override {
fprintf(stderr, "got header: '%s': '%s'\n", name.c_str(), value.c_str());
}
void handleContent(const Memory &data) override {
fprintf(stderr, "got data: %zu bytes\n", data.size);
fwrite(data.data, 1, data.size, stdout);
}
void handleFailure(const string &reason) override {
fprintf(stderr, "got FAILURE: '%s'\n", reason.c_str());
}
};
int
App::Main()
{
if (_argc != 4) {
printf("usage: dumpurl <host> <port> <url>\n");
return -1;
}
MyHttpHandler myHandler;
bool ok = HttpClient::fetch(ServerSpec(_argv[1], atoi(_argv[2])), _argv[3], myHandler);
return ok ? 0 : 1;
}
int main(int argc, char **argv) {
App app;
return app.Entry(argc, argv);
}
|