aboutsummaryrefslogtreecommitdiffstats
path: root/yql/tools/yqlrun/http/servlet.h
blob: 25b1e561d3e1e224725ae512e209f9dcf7a6981d (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once

#include <library/cpp/http/misc/httpcodes.h>
#include <library/cpp/http/misc/httpreqdata.h>
#include <library/cpp/http/io/stream.h>

#include <util/memory/blob.h>


namespace NYql {
namespace NHttp {

///////////////////////////////////////////////////////////////////////////////
// THttpError
///////////////////////////////////////////////////////////////////////////////
class THttpError: public yexception
{
public:
    inline THttpError(HttpCodes code)
        : Code_(code)
    {
    }

    inline HttpCodes GetCode() const {
        return Code_;
    }

private:
    HttpCodes Code_;
};

///////////////////////////////////////////////////////////////////////////////
// TRequest & TResponse
///////////////////////////////////////////////////////////////////////////////
struct TRequest
{
    const THttpInput& Input;
    const TServerRequestData& RD;
    const TBlob& Body;
};

struct TResponse
{
    HttpCodes Code;
    THttpHeaders Headers;
    TBlob Body;
    TString ContentType;

    inline TResponse()
        : Code(HTTP_OK)
        , ContentType(TStringBuf("text/plain"))
    {
    }

    void OutTo(IOutputStream& out) const;
};

///////////////////////////////////////////////////////////////////////////////
// IServlet
///////////////////////////////////////////////////////////////////////////////
class IServlet: private TNonCopyable
{
public:
    virtual ~IServlet() = default;

    virtual void DoGet(const TRequest&, TResponse& resp) const {
        resp.Code = HttpCodes::HTTP_NOT_IMPLEMENTED;
    }

    virtual void DoPost(const TRequest&, TResponse& resp) const {
        resp.Code = HttpCodes::HTTP_NOT_IMPLEMENTED;
    }
};

} // namspace NNttp
} // namspace NYql