]>
Commit | Line | Data |
---|---|---|
8822ebee | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
8822ebee | 3 | * |
bbc27441 AJ |
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. | |
8822ebee AR |
7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 16 Cache Manager API */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
8822ebee AR |
12 | #include "base/AsyncJobCalls.h" |
13 | #include "base/TextException.h" | |
1b76e6c1 | 14 | #include "comm/Connection.h" |
602d9612 | 15 | #include "CommCalls.h" |
8822ebee | 16 | #include "errorpage.h" |
582c2af2 | 17 | #include "globals.h" |
8822ebee AR |
18 | #include "HttpReply.h" |
19 | #include "HttpRequest.h" | |
20 | #include "ipc/Port.h" | |
21 | #include "mgr/Forwarder.h" | |
22 | #include "mgr/Request.h" | |
23 | #include "SquidTime.h" | |
24 | #include "Store.h" | |
25 | ||
8822ebee AR |
26 | CBDATA_NAMESPACED_CLASS_INIT(Mgr, Forwarder); |
27 | ||
1b76e6c1 | 28 | Mgr::Forwarder::Forwarder(const Comm::ConnectionPointer &aConn, const ActionParams &aParams, |
d9fc6862 | 29 | HttpRequest* aRequest, StoreEntry* anEntry): |
f53969cc SM |
30 | Ipc::Forwarder(new Request(KidIdentifier, 0, aConn, aParams), 10), |
31 | httpRequest(aRequest), entry(anEntry), conn(aConn) | |
8822ebee | 32 | { |
1b76e6c1 AJ |
33 | debugs(16, 5, HERE << conn); |
34 | Must(Comm::IsConnOpen(conn)); | |
51ea0904 | 35 | Must(httpRequest != NULL); |
8822ebee AR |
36 | Must(entry != NULL); |
37 | ||
51ea0904 | 38 | HTTPMSGLOCK(httpRequest); |
1bfe9ade | 39 | entry->lock("Mgr::Forwarder"); |
8822ebee AR |
40 | EBIT_SET(entry->flags, ENTRY_FWD_HDR_WAIT); |
41 | ||
42 | closer = asyncCall(16, 5, "Mgr::Forwarder::noteCommClosed", | |
d9fc6862 | 43 | CommCbMemFunT<Forwarder, CommCloseCbParams>(this, &Forwarder::noteCommClosed)); |
1b76e6c1 | 44 | comm_add_close_handler(conn->fd, closer); |
8822ebee AR |
45 | } |
46 | ||
47 | Mgr::Forwarder::~Forwarder() | |
48 | { | |
49 | debugs(16, 5, HERE); | |
51ea0904 | 50 | Must(httpRequest != NULL); |
8822ebee | 51 | Must(entry != NULL); |
8822ebee | 52 | |
51ea0904 | 53 | HTTPMSGUNLOCK(httpRequest); |
8822ebee | 54 | entry->unregisterAbort(); |
1bfe9ade | 55 | entry->unlock("Mgr::Forwarder"); |
51ea0904 | 56 | cleanup(); |
8822ebee AR |
57 | } |
58 | ||
59 | /// closes our copy of the client HTTP connection socket | |
60 | void | |
51ea0904 | 61 | Mgr::Forwarder::cleanup() |
d9fc6862 | 62 | { |
1b76e6c1 | 63 | if (Comm::IsConnOpen(conn)) { |
8822ebee | 64 | if (closer != NULL) { |
1b76e6c1 | 65 | comm_remove_close_handler(conn->fd, closer); |
8822ebee AR |
66 | closer = NULL; |
67 | } | |
1b76e6c1 | 68 | conn->close(); |
8822ebee | 69 | } |
1b76e6c1 | 70 | conn = NULL; |
8822ebee AR |
71 | } |
72 | ||
73 | void | |
51ea0904 | 74 | Mgr::Forwarder::handleError() |
8822ebee | 75 | { |
51ea0904 | 76 | debugs(16, DBG_CRITICAL, "ERROR: uri " << entry->url() << " exceeds buffer size"); |
f11c8e2f | 77 | sendError(new ErrorState(ERR_INVALID_URL, Http::scUriTooLong, httpRequest)); |
51ea0904 | 78 | mustStop("long URI"); |
8822ebee AR |
79 | } |
80 | ||
81 | void | |
51ea0904 | 82 | Mgr::Forwarder::handleTimeout() |
8822ebee | 83 | { |
955394ce | 84 | sendError(new ErrorState(ERR_LIFETIME_EXP, Http::scRequestTimeout, httpRequest)); |
51ea0904 | 85 | Ipc::Forwarder::handleTimeout(); |
8822ebee AR |
86 | } |
87 | ||
51ea0904 | 88 | void |
ced8def3 | 89 | Mgr::Forwarder::handleException(const std::exception &e) |
8822ebee | 90 | { |
1b76e6c1 | 91 | if (entry != NULL && httpRequest != NULL && Comm::IsConnOpen(conn)) |
955394ce | 92 | sendError(new ErrorState(ERR_INVALID_RESP, Http::scInternalServerError, httpRequest)); |
51ea0904 | 93 | Ipc::Forwarder::handleException(e); |
8822ebee AR |
94 | } |
95 | ||
96 | /// called when the client socket gets closed by some external force | |
97 | void | |
ced8def3 | 98 | Mgr::Forwarder::noteCommClosed(const CommCloseCbParams &) |
8822ebee AR |
99 | { |
100 | debugs(16, 5, HERE); | |
1b76e6c1 | 101 | conn = NULL; // needed? |
8822ebee AR |
102 | mustStop("commClosed"); |
103 | } | |
104 | ||
105 | /// called when Coordinator starts processing the request | |
106 | void | |
107 | Mgr::Forwarder::handleRemoteAck() | |
108 | { | |
51ea0904 | 109 | Ipc::Forwarder::handleRemoteAck(); |
8822ebee | 110 | |
51ea0904 | 111 | Must(entry != NULL); |
8822ebee AR |
112 | EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT); |
113 | entry->complete(); | |
114 | } | |
115 | ||
51ea0904 | 116 | /// send error page |
8822ebee | 117 | void |
51ea0904 | 118 | Mgr::Forwarder::sendError(ErrorState *error) |
8822ebee AR |
119 | { |
120 | debugs(16, 3, HERE); | |
8822ebee AR |
121 | Must(error != NULL); |
122 | Must(entry != NULL); | |
51ea0904 | 123 | Must(httpRequest != NULL); |
8822ebee AR |
124 | |
125 | EBIT_CLR(entry->flags, ENTRY_FWD_HDR_WAIT); | |
126 | entry->buffer(); | |
127 | entry->replaceHttpReply(error->BuildHttpReply()); | |
128 | entry->expires = squid_curtime; | |
913524f0 | 129 | delete error; |
8822ebee AR |
130 | entry->flush(); |
131 | entry->complete(); | |
8822ebee | 132 | } |
f53969cc | 133 |