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