]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Forwarder.cc
2 * Copyright (C) 1996-2014 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 "base/AsyncJobCalls.h"
13 #include "base/TextException.h"
14 #include "comm/Connection.h"
15 #include "CommCalls.h"
16 #include "errorpage.h"
18 #include "HttpReply.h"
19 #include "HttpRequest.h"
21 #include "mgr/Forwarder.h"
22 #include "mgr/Request.h"
23 #include "SquidTime.h"
26 CBDATA_NAMESPACED_CLASS_INIT(Mgr
, Forwarder
);
28 Mgr::Forwarder::Forwarder(const Comm::ConnectionPointer
&aConn
, const ActionParams
&aParams
,
29 HttpRequest
* aRequest
, StoreEntry
* anEntry
):
30 Ipc::Forwarder(new Request(KidIdentifier
, 0, aConn
, aParams
), 10),
31 httpRequest(aRequest
), entry(anEntry
), conn(aConn
)
33 debugs(16, 5, HERE
<< conn
);
34 Must(Comm::IsConnOpen(conn
));
35 Must(httpRequest
!= NULL
);
38 HTTPMSGLOCK(httpRequest
);
39 entry
->lock("Mgr::Forwarder");
40 EBIT_SET(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
42 closer
= asyncCall(16, 5, "Mgr::Forwarder::noteCommClosed",
43 CommCbMemFunT
<Forwarder
, CommCloseCbParams
>(this, &Forwarder::noteCommClosed
));
44 comm_add_close_handler(conn
->fd
, closer
);
47 Mgr::Forwarder::~Forwarder()
50 Must(httpRequest
!= NULL
);
53 HTTPMSGUNLOCK(httpRequest
);
54 entry
->unregisterAbort();
55 entry
->unlock("Mgr::Forwarder");
59 /// closes our copy of the client HTTP connection socket
61 Mgr::Forwarder::cleanup()
63 if (Comm::IsConnOpen(conn
)) {
65 comm_remove_close_handler(conn
->fd
, closer
);
74 Mgr::Forwarder::handleError()
76 debugs(16, DBG_CRITICAL
, "ERROR: uri " << entry
->url() << " exceeds buffer size");
77 sendError(new ErrorState(ERR_INVALID_URL
, Http::scUriTooLong
, httpRequest
));
82 Mgr::Forwarder::handleTimeout()
84 sendError(new ErrorState(ERR_LIFETIME_EXP
, Http::scRequestTimeout
, httpRequest
));
85 Ipc::Forwarder::handleTimeout();
89 Mgr::Forwarder::handleException(const std::exception
& e
)
91 if (entry
!= NULL
&& httpRequest
!= NULL
&& Comm::IsConnOpen(conn
))
92 sendError(new ErrorState(ERR_INVALID_RESP
, Http::scInternalServerError
, httpRequest
));
93 Ipc::Forwarder::handleException(e
);
96 /// called when the client socket gets closed by some external force
98 Mgr::Forwarder::noteCommClosed(const CommCloseCbParams
& params
)
101 conn
= NULL
; // needed?
102 mustStop("commClosed");
105 /// called when Coordinator starts processing the request
107 Mgr::Forwarder::handleRemoteAck()
109 Ipc::Forwarder::handleRemoteAck();
112 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
118 Mgr::Forwarder::sendError(ErrorState
*error
)
123 Must(httpRequest
!= NULL
);
125 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
127 entry
->replaceHttpReply(error
->BuildHttpReply());
128 entry
->expires
= squid_curtime
;