summaryrefslogtreecommitdiffstats
path: root/vbench/src/apps/dumpurl/dumpurl.cpp
blob: 5a0c1ab8e2c6857a3b627a11f32c3a512b106eb7 (plain) (blame)
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
45
46
// Copyright 2017 Yahoo Holdings. 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>
#include <vespa/vespalib/net/crypto_engine.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;
    }
    auto null_crypto = std::make_shared<vespalib::NullCryptoEngine>();
    MyHttpHandler myHandler;
    bool ok = HttpClient::fetch(*null_crypto, 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);
}