]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Forwarder.cc
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 16 Cache Manager API */
12 #include "AccessLogEntry.h"
13 #include "base/AsyncJobCalls.h"
14 #include "base/TextException.h"
15 #include "comm/Connection.h"
16 #include "CommCalls.h"
17 #include "errorpage.h"
19 #include "HttpReply.h"
20 #include "HttpRequest.h"
22 #include "mgr/Forwarder.h"
23 #include "mgr/Request.h"
24 #include "SquidTime.h"
27 CBDATA_NAMESPACED_CLASS_INIT(Mgr
, Forwarder
);
29 Mgr::Forwarder::Forwarder(const Comm::ConnectionPointer
&aConn
, const ActionParams
&aParams
,
30 HttpRequest
* aRequest
, StoreEntry
* anEntry
, const AccessLogEntryPointer
&anAle
):
31 // TODO: Add virtual Forwarder::makeRequest() to avoid prematurely creating
32 // this dummy request with a dummy ID that are finalized by Ipc::Forwarder.
33 // Same for Snmp::Forwarder.
34 Ipc::Forwarder(new Request(KidIdentifier
, Ipc::RequestId(/*XXX*/), aConn
, aParams
), 10),
35 httpRequest(aRequest
), entry(anEntry
), conn(aConn
), ale(anAle
)
37 debugs(16, 5, HERE
<< conn
);
38 Must(Comm::IsConnOpen(conn
));
39 Must(httpRequest
!= NULL
);
42 HTTPMSGLOCK(httpRequest
);
43 entry
->lock("Mgr::Forwarder");
45 closer
= asyncCall(16, 5, "Mgr::Forwarder::noteCommClosed",
46 CommCbMemFunT
<Forwarder
, CommCloseCbParams
>(this, &Forwarder::noteCommClosed
));
47 comm_add_close_handler(conn
->fd
, closer
);
50 Mgr::Forwarder::~Forwarder()
54 entry
->unlock("Mgr::Forwarder");
56 HTTPMSGUNLOCK(httpRequest
);
60 /// closes our copy of the client HTTP connection socket
62 Mgr::Forwarder::swanSong()
64 if (Comm::IsConnOpen(conn
)) {
66 comm_remove_close_handler(conn
->fd
, closer
);
72 Ipc::Forwarder::swanSong();
76 Mgr::Forwarder::handleError()
78 debugs(16, DBG_CRITICAL
, "ERROR: uri " << entry
->url() << " exceeds buffer size");
79 sendError(new ErrorState(ERR_INVALID_URL
, Http::scUriTooLong
, httpRequest
, ale
));
84 Mgr::Forwarder::handleTimeout()
86 sendError(new ErrorState(ERR_LIFETIME_EXP
, Http::scRequestTimeout
, httpRequest
, ale
));
87 Ipc::Forwarder::handleTimeout();
91 Mgr::Forwarder::handleException(const std::exception
&e
)
93 if (entry
!= NULL
&& httpRequest
!= NULL
&& Comm::IsConnOpen(conn
))
94 sendError(new ErrorState(ERR_INVALID_RESP
, Http::scInternalServerError
, httpRequest
, ale
));
95 Ipc::Forwarder::handleException(e
);
98 /// called when the client socket gets closed by some external force
100 Mgr::Forwarder::noteCommClosed(const CommCloseCbParams
&)
103 conn
= NULL
; // needed?
104 mustStop("commClosed");
109 Mgr::Forwarder::sendError(ErrorState
*error
)
114 Must(httpRequest
!= NULL
);
117 entry
->replaceHttpReply(error
->BuildHttpReply());
118 entry
->expires
= squid_curtime
;