4 * DEBUG: section 16 Cache Manager API
9 #include "base/AsyncJobCalls.h"
10 #include "base/TextException.h"
11 #include "CommCalls.h"
12 #include "comm/Connection.h"
13 #include "errorpage.h"
15 #include "HttpReply.h"
16 #include "HttpRequest.h"
18 #include "mgr/Forwarder.h"
19 #include "mgr/Request.h"
20 #include "SquidTime.h"
23 CBDATA_NAMESPACED_CLASS_INIT(Mgr
, Forwarder
);
25 Mgr::Forwarder::Forwarder(const Comm::ConnectionPointer
&aConn
, const ActionParams
&aParams
,
26 HttpRequest
* aRequest
, StoreEntry
* anEntry
):
27 Ipc::Forwarder(new Request(KidIdentifier
, 0, aConn
, aParams
), 10),
28 httpRequest(aRequest
), entry(anEntry
), conn(aConn
)
30 debugs(16, 5, HERE
<< conn
);
31 Must(Comm::IsConnOpen(conn
));
32 Must(httpRequest
!= NULL
);
35 HTTPMSGLOCK(httpRequest
);
37 EBIT_SET(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
39 closer
= asyncCall(16, 5, "Mgr::Forwarder::noteCommClosed",
40 CommCbMemFunT
<Forwarder
, CommCloseCbParams
>(this, &Forwarder::noteCommClosed
));
41 comm_add_close_handler(conn
->fd
, closer
);
44 Mgr::Forwarder::~Forwarder()
47 Must(httpRequest
!= NULL
);
50 HTTPMSGUNLOCK(httpRequest
);
51 entry
->unregisterAbort();
56 /// closes our copy of the client HTTP connection socket
58 Mgr::Forwarder::cleanup()
60 if (Comm::IsConnOpen(conn
)) {
62 comm_remove_close_handler(conn
->fd
, closer
);
71 Mgr::Forwarder::handleError()
73 debugs(16, DBG_CRITICAL
, "ERROR: uri " << entry
->url() << " exceeds buffer size");
74 sendError(new ErrorState(ERR_INVALID_URL
, HTTP_REQUEST_URI_TOO_LARGE
, httpRequest
));
79 Mgr::Forwarder::handleTimeout()
81 sendError(new ErrorState(ERR_LIFETIME_EXP
, HTTP_REQUEST_TIMEOUT
, httpRequest
));
82 Ipc::Forwarder::handleTimeout();
86 Mgr::Forwarder::handleException(const std::exception
& e
)
88 if (entry
!= NULL
&& httpRequest
!= NULL
&& Comm::IsConnOpen(conn
))
89 sendError(new ErrorState(ERR_INVALID_RESP
, HTTP_INTERNAL_SERVER_ERROR
, httpRequest
));
90 Ipc::Forwarder::handleException(e
);
93 /// called when the client socket gets closed by some external force
95 Mgr::Forwarder::noteCommClosed(const CommCloseCbParams
& params
)
98 conn
= NULL
; // needed?
99 mustStop("commClosed");
102 /// called when Coordinator starts processing the request
104 Mgr::Forwarder::handleRemoteAck()
106 Ipc::Forwarder::handleRemoteAck();
109 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
115 Mgr::Forwarder::sendError(ErrorState
*error
)
120 Must(httpRequest
!= NULL
);
122 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
124 entry
->replaceHttpReply(error
->BuildHttpReply());
125 entry
->expires
= squid_curtime
;