Action.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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 "comm/Connection.h"
13#include "HttpReply.h"
14#include "ipc/Port.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 "Store.h"
23
25{
26 Must(cmd != nullptr);
27 Must(cmd->profile != nullptr);
28}
29
31{
32}
33
34const Mgr::Command &
36{
37 Must(cmd != nullptr);
38 return *cmd;
39}
40
41bool
43{
44 return command().profile->isAtomic;
45}
46
47const char*
49{
50 return command().profile->name;
51}
52
55{
56 const ActionParams &params = command().params;
57 const char *uri = params.httpUri.termedBuf();
58 return storeCreateEntry(uri, uri, params.httpFlags, params.httpMethod);
59}
60
61void
63{
64}
65
66void
68{
69 debugs(16, 5, MYNAME);
70
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;
76 collect();
77 sendResponse(request.requestId);
78}
79
80void
82{
83 Response response(requestId, this);
84 Ipc::TypedMsgHdr message;
85 response.pack(message);
87}
88
89void
90Mgr::Action::run(StoreEntry* entry, bool writeHttpHeader)
91{
92 debugs(16, 5, MYNAME);
93 collect();
94 fillEntry(entry, writeHttpHeader);
95}
96
97void
98Mgr::Action::fillEntry(StoreEntry* entry, bool writeHttpHeader)
99{
100 debugs(16, 5, MYNAME);
101 entry->buffer();
102
103 if (writeHttpHeader) {
104 HttpReply *rep = new HttpReply;
105 rep->setHeaders(Http::scOkay, nullptr, contentType(), -1, squid_curtime, squid_curtime);
106 // Allow cachemgr and other XHR scripts access to our version string
107 const ActionParams &params = 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");
112#endif
113 rep->header.putExt("Access-Control-Expose-Headers","Server");
114 }
115 entry->replaceHttpReply(rep);
116 }
117
118 dump(entry);
119
120 entry->flush();
121
122 if (atomic())
123 entry->complete();
124}
125
time_t squid_curtime
Definition: stub_libtime.cc:20
#define Must(condition)
Definition: TextException.h:71
void putExt(const char *name, const char *value)
Definition: HttpHeader.cc:1109
void setHeaders(Http::StatusCode status, const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires)
Definition: HttpReply.cc:167
HttpHeader header
Definition: Message.h:74
static String CoordinatorAddr()
get the IPC message address for coordinator process
Definition: Port.cc:65
struct msghdr with a known type, fixed-size I/O and control buffers
Definition: TypedMsgHdr.h:35
Cache Manager Action parameters extracted from the user request.
Definition: ActionParams.h:24
String httpOrigin
HTTP Origin: header (if any)
Definition: ActionParams.h:36
String httpUri
HTTP request URI.
Definition: ActionParams.h:33
RequestFlags httpFlags
HTTP request flags.
Definition: ActionParams.h:35
HttpRequestMethod httpMethod
HTTP request method.
Definition: ActionParams.h:34
Action(const CommandPointer &aCmd)
Definition: Action.cc:24
virtual ~Action()
Definition: Action.cc:30
void fillEntry(StoreEntry *entry, bool writeHttpHeader)
prepare store entry, dump info, close store entry (if possible)
Definition: Action.cc:98
const Command & command() const
the cause of this action
Definition: Action.cc:35
void sendResponse(Ipc::RequestId)
notify Coordinator that this action is done with local processing
Definition: Action.cc:81
virtual void respond(const Request &request)
respond to Coordinator request; default is to collect and sendResponse
Definition: Action.cc:67
StoreEntry * createStoreEntry() const
creates store entry from params
Definition: Action.cc:54
bool atomic() const
dump() call writes everything before returning
Definition: Action.cc:42
const char * name() const
label as seen in the cache manager menu
Definition: Action.cc:48
const CommandPointer cmd
the command that caused this action
Definition: Action.h:86
virtual void add(const Action &action)
incrementally merge in remote information (of the same action type)
Definition: Action.cc:62
void run(StoreEntry *entry, bool writeHttpHeader)
collect + fillEntry: collect local information and fill the store entry
Definition: Action.cc:90
combined hard-coded action profile with user-supplied action parameters
Definition: Command.h:22
cache manager request
Definition: Request.h:23
virtual void pack(Ipc::TypedMsgHdr &msg) const
prepare for sendmsg()
Definition: Response.cc:43
virtual void buffer()
Definition: store.cc:1568
virtual void flush()
Definition: store.cc:1579
void complete()
Definition: store.cc:1004
void replaceHttpReply(const HttpReplyPointer &, const bool andStartWriting=true)
Definition: store.cc:1672
char const * termedBuf() const
Definition: SquidString.h:92
size_type size() const
Definition: SquidString.h:73
#define MYNAME
Definition: Stream.h:238
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
@ scOkay
Definition: StatusCode.h:26
void SendMessage(const String &toAddress, const TypedMsgHdr &message)
Definition: UdsOp.cc:188
StoreEntry * storeCreateEntry(const char *url, const char *logUrl, const RequestFlags &flags, const HttpRequestMethod &method)
Definition: store.cc:732
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors