-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHttpServiceDelegate
More file actions
85 lines (67 loc) · 1.92 KB
/
HttpServiceDelegate
File metadata and controls
85 lines (67 loc) · 1.92 KB
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
78
79
80
81
82
83
84
85
/*
* Copyright (C) 2021 Frank Mertens.
*
* Distribution and use is allowed under the terms of the GNU General Public License version 3
* (see CoreComponents/LICENSE-gpl-3.0).
*
*/
#pragma once
#include <cc/httpLogging>
#include <cc/HttpRequest>
#include <cc/HttpResponseGenerator>
#include <cc/Format>
namespace cc {
class HttpServerConfig;
class HttpServiceWorker;
class HttpServiceWorkerState;
class HttpClientConnection;
class HttpServiceInstance;
class HttpLoggingServiceInstance;
/** \class HttpServiceDelegate cc/HttpServiceDelegate
* \ingroup http_server
* \brief %Delegate used by the worker threads to process HTTP requests
*/
class HttpServiceDelegate: public Object
{
public:
/** Create null delivery delegate
*/
HttpServiceDelegate() = default;
/** %Process a HTTP request
*/
void process(const HttpRequest &request)
{
me().process(request);
}
/** %Run custom protocol
*/
void upgrade(Stream &stream)
{
me().upgrade(stream);
}
protected:
friend class HttpServiceWorkerState;
/** \brief Internal state
*/
struct State: public Object::State
{
State() = default;
virtual void process(const HttpRequest &request) = 0;
virtual void upgrade(Stream &stream) {}
const HttpServerConfig &nodeConfig() const;
const HttpServiceInstance &serviceInstance() const;
const HttpLoggingServiceInstance &errorLoggingInstance() const;
HttpClientConnection &client();
HttpResponseGenerator &response();
private:
friend class HttpServiceWorkerState;
HttpServiceWorkerState *workerState_ { nullptr };
};
explicit HttpServiceDelegate(State *newState):
Object{newState}
{}
State *operator->() { return &me(); }
State &me() { return Object::me.as<State>(); }
const State &me() const { return Object::me.as<State>(); }
};
} // namespace cc