aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/net/http/http_server.cpp
blob: a307a4eca4f0dca85841822af81aedf9a57f2ff2 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "http_server.h"
#include <vespa/vespalib/net/crypto_engine.h>
#include <vespa/vespalib/net/connection_auth_context.h>

namespace vespalib {

void
HttpServer::get(Portal::GetRequest req)
{
    auto response = _handler_repo.get(req.get_host(), req.get_path(), req.export_params(), req.auth_context());
    if (response.failed()) {
        req.respond_with_error(response.status_code(), response.status_message());
    } else {
        req.respond_with_content("application/json", response.payload());
    }
}

//-----------------------------------------------------------------------------

HttpServer::HttpServer(int port_in)
    : _handler_repo(),
      _server(Portal::create(CryptoEngine::get_default(), port_in)),
      _root(_server->bind("/", *this))
{
}

HttpServer::~HttpServer()
{
    _root.reset();
}

} // namespace vespalib