]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpControlMsg.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / HttpControlMsg.h
1 /*
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_HTTP_CONTROL_MSG_H
10 #define SQUID_HTTP_CONTROL_MSG_H
11
12 #include "base/AsyncCall.h"
13 #include "HttpReply.h"
14
15 class HttpControlMsg;
16
17 /*
18 * This API exists to throttle forwarding of 1xx messages from the server
19 * side (Source == HttpStateData) to the client side (Sink == ConnStateData).
20 *
21 * Without throttling, Squid would have to drop some 1xx responses to
22 * avoid DoS attacks that send many 1xx responses without reading them.
23 * Dropping 1xx responses without violating HTTP is as complex as throttling.
24 */
25
26 /// sends a single control message, notifying the Sink
27 class HttpControlMsgSink: public virtual AsyncJob
28 {
29 public:
30 HttpControlMsgSink(): AsyncJob("unused") {}
31
32 /// called to send the 1xx message and notify the Source
33 virtual void sendControlMsg(HttpControlMsg msg) = 0;
34 };
35
36 /// bundles HTTP 1xx reply and the "successfully forwarded" callback
37 class HttpControlMsg
38 {
39 public:
40 typedef AsyncCall::Pointer Callback;
41
42 HttpControlMsg(const HttpReply::Pointer &aReply, const Callback &aCallback):
43 reply(aReply), cbSuccess(aCallback) {}
44
45 public:
46 HttpReply::Pointer reply; ///< the 1xx message being forwarded
47 Callback cbSuccess; ///< called after successfully writing the 1xx message
48
49 // We could add an API to notify of send failures as well, but the
50 // current Source and Sink are tied via Store anyway, so the Source
51 // will know, eventually, if the Sink is gone or otherwise failed.
52 };
53
54 inline std::ostream &
55 operator <<(std::ostream &os, const HttpControlMsg &msg)
56 {
57 return os << msg.reply << ", " << msg.cbSuccess;
58 }
59
60 #endif /* SQUID_HTTP_CONTROL_MSG_H */
61