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"
14 #include "HttpReply.h"
15 #include "HttpRequest.h"
17 #include "mgr/Forwarder.h"
18 #include "mgr/Request.h"
19 #include "SquidTime.h"
23 CBDATA_NAMESPACED_CLASS_INIT(Mgr
, Forwarder
);
26 Mgr::Forwarder::Forwarder(const Comm::ConnectionPointer
&aConn
, const ActionParams
&aParams
,
27 HttpRequest
* aRequest
, StoreEntry
* anEntry
):
28 Ipc::Forwarder(new Request(KidIdentifier
, 0, aConn
, aParams
), 10),
29 httpRequest(aRequest
), entry(anEntry
), conn(aConn
)
31 debugs(16, 5, HERE
<< conn
);
32 Must(Comm::IsConnOpen(conn
));
33 Must(httpRequest
!= NULL
);
36 HTTPMSGLOCK(httpRequest
);
38 EBIT_SET(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
40 closer
= asyncCall(16, 5, "Mgr::Forwarder::noteCommClosed",
41 CommCbMemFunT
<Forwarder
, CommCloseCbParams
>(this, &Forwarder::noteCommClosed
));
42 comm_add_close_handler(conn
->fd
, closer
);
45 Mgr::Forwarder::~Forwarder()
48 Must(httpRequest
!= NULL
);
51 HTTPMSGUNLOCK(httpRequest
);
52 entry
->unregisterAbort();
57 /// closes our copy of the client HTTP connection socket
59 Mgr::Forwarder::cleanup()
61 if (Comm::IsConnOpen(conn
)) {
63 comm_remove_close_handler(conn
->fd
, closer
);
72 Mgr::Forwarder::handleError()
74 debugs(16, DBG_CRITICAL
, "ERROR: uri " << entry
->url() << " exceeds buffer size");
75 sendError(new ErrorState(ERR_INVALID_URL
, HTTP_REQUEST_URI_TOO_LARGE
, httpRequest
));
80 Mgr::Forwarder::handleTimeout()
82 sendError(new ErrorState(ERR_LIFETIME_EXP
, HTTP_REQUEST_TIMEOUT
, httpRequest
));
83 Ipc::Forwarder::handleTimeout();
87 Mgr::Forwarder::handleException(const std::exception
& e
)
89 if (entry
!= NULL
&& httpRequest
!= NULL
&& Comm::IsConnOpen(conn
))
90 sendError(new ErrorState(ERR_INVALID_RESP
, HTTP_INTERNAL_SERVER_ERROR
, httpRequest
));
91 Ipc::Forwarder::handleException(e
);
94 /// called when the client socket gets closed by some external force
96 Mgr::Forwarder::noteCommClosed(const CommCloseCbParams
& params
)
99 conn
= NULL
; // needed?
100 mustStop("commClosed");
103 /// called when Coordinator starts processing the request
105 Mgr::Forwarder::handleRemoteAck()
107 Ipc::Forwarder::handleRemoteAck();
110 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
116 Mgr::Forwarder::sendError(ErrorState
*error
)
121 Must(httpRequest
!= NULL
);
123 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
125 entry
->replaceHttpReply(error
->BuildHttpReply());
126 entry
->expires
= squid_curtime
;