]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Action.cc
129e9c4ebc9b59e70e8419c7891fb2af52b75f7c
2 * Copyright (C) 1996-2021 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"
22 #include "SquidTime.h"
25 Mgr::Action::Action(const Command::Pointer
&aCmd
): cmd(aCmd
)
28 Must(cmd
->profile
!= NULL
);
31 Mgr::Action::~Action()
36 Mgr::Action::command() const
43 Mgr::Action::atomic() const
45 return command().profile
->isAtomic
;
49 Mgr::Action::name() const
51 return command().profile
->name
;
55 Mgr::Action::createStoreEntry() const
57 const ActionParams
¶ms
= command().params
;
58 const char *uri
= params
.httpUri
.termedBuf();
59 return storeCreateEntry(uri
, uri
, params
.httpFlags
, params
.httpMethod
);
63 Mgr::Action::add(const Action
&)
68 Mgr::Action::respond(const Request
&request
)
72 // Assume most kid classes are fully aggregatable (i.e., they do not dump
73 // local info at all). Do not import the remote HTTP fd into our Comm
74 // space; collect and send an IPC msg with collected info to Coordinator.
75 ::close(request
.conn
->fd
);
76 request
.conn
->fd
= -1;
78 sendResponse(request
.requestId
);
82 Mgr::Action::sendResponse(const Ipc::RequestId requestId
)
84 Response
response(requestId
, this);
85 Ipc::TypedMsgHdr message
;
86 response
.pack(message
);
87 Ipc::SendMessage(Ipc::Port::CoordinatorAddr(), message
);
91 Mgr::Action::run(StoreEntry
* entry
, bool writeHttpHeader
)
95 fillEntry(entry
, writeHttpHeader
);
99 Mgr::Action::fillEntry(StoreEntry
* entry
, bool writeHttpHeader
)
104 if (writeHttpHeader
) {
105 HttpReply
*rep
= new HttpReply
;
106 rep
->setHeaders(Http::scOkay
, NULL
, contentType(), -1, squid_curtime
, squid_curtime
);
107 // Allow cachemgr and other XHR scripts access to our version string
108 const ActionParams
¶ms
= command().params
;
109 if (params
.httpOrigin
.size() > 0) {
110 rep
->header
.putExt("Access-Control-Allow-Origin", params
.httpOrigin
.termedBuf());
111 #if HAVE_AUTH_MODULE_BASIC
112 rep
->header
.putExt("Access-Control-Allow-Credentials","true");
114 rep
->header
.putExt("Access-Control-Expose-Headers","Server");
116 entry
->replaceHttpReply(rep
);