]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Action.cc
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 16 Cache Manager API */
12 #include "comm/Connection.h"
13 #include "HttpReply.h"
15 #include "mgr/Action.h"
16 #include "mgr/ActionCreator.h"
17 #include "mgr/ActionParams.h"
18 #include "mgr/ActionProfile.h"
19 #include "mgr/Command.h"
20 #include "mgr/Request.h"
21 #include "mgr/Response.h"
24 Mgr::Action::Action(const Command::Pointer
&aCmd
): cmd(aCmd
)
27 Must(cmd
->profile
!= NULL
);
30 Mgr::Action::~Action()
35 Mgr::Action::command() const
42 Mgr::Action::atomic() const
44 return command().profile
->isAtomic
;
48 Mgr::Action::name() const
50 return command().profile
->name
;
54 Mgr::Action::createStoreEntry() const
56 const ActionParams
¶ms
= command().params
;
57 const char *uri
= params
.httpUri
.termedBuf();
58 return storeCreateEntry(uri
, uri
, params
.httpFlags
, params
.httpMethod
);
62 Mgr::Action::add(const Action
&)
67 Mgr::Action::respond(const Request
&request
)
69 debugs(16, 5, MYNAME
);
71 // Assume most kid classes are fully aggregatable (i.e., they do not dump
72 // local info at all). Do not import the remote HTTP fd into our Comm
73 // space; collect and send an IPC msg with collected info to Coordinator.
74 ::close(request
.conn
->fd
);
75 request
.conn
->fd
= -1;
77 sendResponse(request
.requestId
);
81 Mgr::Action::sendResponse(const Ipc::RequestId requestId
)
83 Response
response(requestId
, this);
84 Ipc::TypedMsgHdr message
;
85 response
.pack(message
);
86 Ipc::SendMessage(Ipc::Port::CoordinatorAddr(), message
);
90 Mgr::Action::run(StoreEntry
* entry
, bool writeHttpHeader
)
92 debugs(16, 5, MYNAME
);
94 fillEntry(entry
, writeHttpHeader
);
98 Mgr::Action::fillEntry(StoreEntry
* entry
, bool writeHttpHeader
)
100 debugs(16, 5, MYNAME
);
103 if (writeHttpHeader
) {
104 HttpReply
*rep
= new HttpReply
;
105 rep
->setHeaders(Http::scOkay
, NULL
, contentType(), -1, squid_curtime
, squid_curtime
);
106 // Allow cachemgr and other XHR scripts access to our version string
107 const ActionParams
¶ms
= command().params
;
108 if (params
.httpOrigin
.size() > 0) {
109 rep
->header
.putExt("Access-Control-Allow-Origin", params
.httpOrigin
.termedBuf());
110 #if HAVE_AUTH_MODULE_BASIC
111 rep
->header
.putExt("Access-Control-Allow-Credentials","true");
113 rep
->header
.putExt("Access-Control-Expose-Headers","Server");
115 entry
->replaceHttpReply(rep
);