4 * DEBUG: section 16 Cache Manager API
9 #include "base/AsyncJobCalls.h"
10 #include "base/TextException.h"
11 #include "CommCalls.h"
12 #include "errorpage.h"
13 #include "HttpReply.h"
14 #include "HttpRequest.h"
16 #include "mgr/Forwarder.h"
17 #include "mgr/Request.h"
18 #include "SquidTime.h"
22 CBDATA_NAMESPACED_CLASS_INIT(Mgr
, Forwarder
);
25 Mgr::Forwarder::Forwarder(int aFd
, const ActionParams
&aParams
,
26 HttpRequest
* aRequest
, StoreEntry
* anEntry
):
27 Ipc::Forwarder(new Request(KidIdentifier
, 0, aFd
, aParams
), 10),
28 httpRequest(aRequest
), entry(anEntry
), fd(aFd
)
30 debugs(16, 5, HERE
<< "FD " << fd
);
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(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()
62 comm_remove_close_handler(fd
, closer
);
71 Mgr::Forwarder::handleError()
73 debugs(16, DBG_CRITICAL
, "ERROR: uri " << entry
->url() << " exceeds buffer size");
74 sendError(errorCon(ERR_INVALID_URL
, HTTP_REQUEST_URI_TOO_LARGE
, httpRequest
));
79 Mgr::Forwarder::handleTimeout()
81 sendError(errorCon(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
&& fd
>= 0)
89 sendError(errorCon(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 Must(fd
== params
.fd
);
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
;
127 errorStateFree(error
);