]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Action.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / mgr / Action.cc
1 /*
2 * DEBUG: section 16 Cache Manager API
3 *
4 */
5
6 #include "squid.h"
7 #include "comm/Connection.h"
8 #include "HttpReply.h"
9 #include "ipc/Port.h"
10 #include "mgr/Action.h"
11 #include "mgr/ActionCreator.h"
12 #include "mgr/ActionParams.h"
13 #include "mgr/ActionProfile.h"
14 #include "mgr/Command.h"
15 #include "mgr/Request.h"
16 #include "mgr/Response.h"
17 #include "SquidTime.h"
18 #include "Store.h"
19
20 Mgr::Action::Action(const Command::Pointer &aCmd): cmd(aCmd)
21 {
22 Must(cmd != NULL);
23 Must(cmd->profile != NULL);
24 }
25
26 Mgr::Action::~Action()
27 {
28 }
29
30 const Mgr::Command &
31 Mgr::Action::command() const
32 {
33 Must(cmd != NULL);
34 return *cmd;
35 }
36
37 bool
38 Mgr::Action::atomic() const
39 {
40 return command().profile->isAtomic;
41 }
42
43 const char*
44 Mgr::Action::name() const
45 {
46 return command().profile->name;
47 }
48
49 StoreEntry*
50 Mgr::Action::createStoreEntry() const
51 {
52 const ActionParams &params = command().params;
53 const char *uri = params.httpUri.termedBuf();
54 return storeCreateEntry(uri, uri, params.httpFlags, params.httpMethod);
55 }
56
57 void
58 Mgr::Action::add(const Action& action)
59 {
60 }
61
62 void
63 Mgr::Action::respond(const Request& request)
64 {
65 debugs(16, 5, HERE);
66
67 // Assume most kid classes are fully aggregatable (i.e., they do not dump
68 // local info at all). Do not import the remote HTTP fd into our Comm
69 // space; collect and send an IPC msg with collected info to Coordinator.
70 ::close(request.conn->fd);
71 request.conn->fd = -1;
72 collect();
73 sendResponse(request.requestId);
74 }
75
76 void
77 Mgr::Action::sendResponse(unsigned int requestId)
78 {
79 Response response(requestId, this);
80 Ipc::TypedMsgHdr message;
81 response.pack(message);
82 Ipc::SendMessage(Ipc::coordinatorAddr, message);
83 }
84
85 void
86 Mgr::Action::run(StoreEntry* entry, bool writeHttpHeader)
87 {
88 debugs(16, 5, HERE);
89 collect();
90 fillEntry(entry, writeHttpHeader);
91 }
92
93 void
94 Mgr::Action::fillEntry(StoreEntry* entry, bool writeHttpHeader)
95 {
96 debugs(16, 5, HERE);
97 entry->buffer();
98
99 if (writeHttpHeader) {
100 HttpReply *rep = new HttpReply;
101 rep->setHeaders(Http::scOkay, NULL, "text/plain", -1, squid_curtime, squid_curtime);
102 // Allow cachemgr and other XHR scripts access to our version string
103 const ActionParams &params = command().params;
104 if (params.httpOrigin.size() > 0) {
105 rep->header.putExt("Access-Control-Allow-Origin", params.httpOrigin.termedBuf());
106 #if HAVE_AUTH_MODULE_BASIC
107 rep->header.putExt("Access-Control-Allow-Credentials","true");
108 #endif
109 rep->header.putExt("Access-Control-Expose-Headers","Server");
110 }
111 entry->replaceHttpReply(rep);
112 }
113
114 dump(entry);
115
116 entry->flush();
117
118 if (atomic())
119 entry->complete();
120 }