Forwarder.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 /* DEBUG: section 16 Cache Manager API */
10 
11 #include "squid.h"
12 #include "base/AsyncJobCalls.h"
13 #include "base/TextException.h"
14 #include "comm/Connection.h"
15 #include "CommCalls.h"
16 #include "errorpage.h"
17 #include "globals.h"
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 
26 CBDATA_NAMESPACED_CLASS_INIT(Mgr, Forwarder);
27 
29  HttpRequest* aRequest, StoreEntry* anEntry):
30  Ipc::Forwarder(new Request(KidIdentifier, 0, aConn, aParams), 10),
31  httpRequest(aRequest), entry(anEntry), conn(aConn)
32 {
33  debugs(16, 5, HERE << conn);
35  Must(httpRequest != NULL);
36  Must(entry != NULL);
37 
39  entry->lock("Mgr::Forwarder");
40 
41  closer = asyncCall(16, 5, "Mgr::Forwarder::noteCommClosed",
44 }
45 
47 {
49  Must(entry);
50  entry->unlock("Mgr::Forwarder");
51  Must(httpRequest);
52  HTTPMSGUNLOCK(httpRequest);
53  });
54 }
55 
57 void
59 {
60  if (Comm::IsConnOpen(conn)) {
61  if (closer != NULL) {
62  comm_remove_close_handler(conn->fd, closer);
63  closer = NULL;
64  }
65  conn->close();
66  }
67  conn = NULL;
69 }
70 
71 void
73 {
74  debugs(16, DBG_CRITICAL, "ERROR: uri " << entry->url() << " exceeds buffer size");
75  sendError(new ErrorState(ERR_INVALID_URL, Http::scUriTooLong, httpRequest));
76  mustStop("long URI");
77 }
78 
79 void
81 {
82  sendError(new ErrorState(ERR_LIFETIME_EXP, Http::scRequestTimeout, httpRequest));
84 }
85 
86 void
87 Mgr::Forwarder::handleException(const std::exception &e)
88 {
89  if (entry != NULL && httpRequest != NULL && Comm::IsConnOpen(conn))
90  sendError(new ErrorState(ERR_INVALID_RESP, Http::scInternalServerError, httpRequest));
92 }
93 
95 void
97 {
98  debugs(16, 5, HERE);
99  conn = NULL; // needed?
100  mustStop("commClosed");
101 }
102 
104 void
106 {
107  debugs(16, 3, HERE);
108  Must(error != NULL);
109  Must(entry != NULL);
110  Must(httpRequest != NULL);
111 
112  entry->buffer();
113  entry->replaceHttpReply(error->BuildHttpReply());
114  entry->expires = squid_curtime;
115  delete error;
116  entry->flush();
117  entry->complete();
118 }
119 
cache manager request
Definition: Request.h:22
virtual void handleException(const std::exception &e)
terminate with an error
Definition: Forwarder.cc:129
#define CBDATA_NAMESPACED_CLASS_INIT(namespace, type)
Definition: cbdata.h:326
virtual void handleTimeout()
Definition: Forwarder.cc:80
void error(char *format,...)
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:160
#define Must(condition)
Like assert() but throws an exception instead of aborting the process.
Definition: TextException.h:69
#define DBG_CRITICAL
Definition: Debug.h:45
int conn
the current server connection FD
Definition: Transport.cc:26
time_t squid_curtime
Definition: stub_time.cc:17
Cache Manager Action parameters extracted from the user request.
Definition: ActionParams.h:23
#define SWALLOW_EXCEPTIONS(code)
Definition: TextException.h:73
AsyncCall * asyncCall(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:156
AsyncCall::Pointer closer
comm_close handler for the HTTP connection
Definition: Forwarder.h:54
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Definition: Connection.cc:24
virtual void handleTimeout()
Definition: Forwarder.cc:122
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
virtual void swanSong()
Definition: Forwarder.cc:67
virtual void swanSong()
closes our copy of the client HTTP connection socket
Definition: Forwarder.cc:58
HttpRequest * httpRequest
HTTP client request for detailing errors.
Definition: Forwarder.h:51
virtual void handleException(const std::exception &e)
terminate with an error
Definition: Forwarder.cc:87
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:153
virtual void handleError()
Definition: Forwarder.cc:72
int KidIdentifier
virtual ~Forwarder()
Definition: Forwarder.cc:46
void noteCommClosed(const CommCloseCbParams &params)
called when the client socket gets closed by some external force
Definition: Forwarder.cc:96
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:149
AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *handler, void *data)
Definition: comm.cc:961
HttpReply * BuildHttpReply(void)
Definition: errorpage.cc:1111
void sendError(ErrorState *error)
send error page
Definition: Forwarder.cc:105
void comm_remove_close_handler(int fd, CLCB *handler, void *data)
Definition: comm.cc:988
StoreEntry * entry
Store entry expecting the response.
Definition: Forwarder.h:52
#define NULL
Definition: types.h:166
Comm::ConnectionPointer conn
HTTP client connection descriptor.
Definition: Forwarder.h:53
Forwarder(const Comm::ConnectionPointer &aConn, const ActionParams &aParams, HttpRequest *aRequest, StoreEntry *anEntry)
Definition: Forwarder.cc:28
void lock(const char *context)
Definition: store.cc:433

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors