]>
Commit | Line | Data |
---|---|---|
8822ebee | 1 | /* |
bbc27441 | 2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors |
8822ebee | 3 | * |
bbc27441 AJ |
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. | |
8822ebee AR |
7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 16 Cache Manager API */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
1b76e6c1 | 12 | #include "comm/Connection.h" |
8822ebee AR |
13 | #include "HttpReply.h" |
14 | #include "ipc/Port.h" | |
8822ebee | 15 | #include "mgr/Action.h" |
602d9612 | 16 | #include "mgr/ActionCreator.h" |
8822ebee AR |
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" | |
23 | #include "Store.h" | |
24 | ||
8822ebee AR |
25 | Mgr::Action::Action(const Command::Pointer &aCmd): cmd(aCmd) |
26 | { | |
27 | Must(cmd != NULL); | |
28 | Must(cmd->profile != NULL); | |
29 | } | |
30 | ||
31 | Mgr::Action::~Action() | |
32 | { | |
33 | } | |
34 | ||
35 | const Mgr::Command & | |
36 | Mgr::Action::command() const | |
37 | { | |
38 | Must(cmd != NULL); | |
39 | return *cmd; | |
40 | } | |
41 | ||
42 | bool | |
43 | Mgr::Action::atomic() const | |
44 | { | |
45 | return command().profile->isAtomic; | |
46 | } | |
47 | ||
48 | const char* | |
49 | Mgr::Action::name() const | |
50 | { | |
51 | return command().profile->name; | |
52 | } | |
53 | ||
54 | StoreEntry* | |
55 | Mgr::Action::createStoreEntry() const | |
56 | { | |
57 | const ActionParams ¶ms = command().params; | |
58 | const char *uri = params.httpUri.termedBuf(); | |
59 | return storeCreateEntry(uri, uri, params.httpFlags, params.httpMethod); | |
60 | } | |
61 | ||
62 | void | |
ced8def3 | 63 | Mgr::Action::add(const Action &) |
8822ebee AR |
64 | { |
65 | } | |
66 | ||
67 | void | |
ced8def3 | 68 | Mgr::Action::respond(const Request &request) |
8822ebee AR |
69 | { |
70 | debugs(16, 5, HERE); | |
71 | ||
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. | |
f7c5a636 AR |
75 | ::close(request.conn->fd); |
76 | request.conn->fd = -1; | |
8822ebee AR |
77 | collect(); |
78 | sendResponse(request.requestId); | |
79 | } | |
80 | ||
81 | void | |
82 | Mgr::Action::sendResponse(unsigned int requestId) | |
83 | { | |
84 | Response response(requestId, this); | |
85 | Ipc::TypedMsgHdr message; | |
86 | response.pack(message); | |
1ee292b7 | 87 | Ipc::SendMessage(Ipc::Port::CoordinatorAddr(), message); |
8822ebee AR |
88 | } |
89 | ||
90 | void | |
91 | Mgr::Action::run(StoreEntry* entry, bool writeHttpHeader) | |
92 | { | |
93 | debugs(16, 5, HERE); | |
94 | collect(); | |
95 | fillEntry(entry, writeHttpHeader); | |
96 | } | |
97 | ||
98 | void | |
99 | Mgr::Action::fillEntry(StoreEntry* entry, bool writeHttpHeader) | |
100 | { | |
101 | debugs(16, 5, HERE); | |
102 | entry->buffer(); | |
103 | ||
104 | if (writeHttpHeader) { | |
105 | HttpReply *rep = new HttpReply; | |
8088f8d0 | 106 | rep->setHeaders(Http::scOkay, NULL, contentType(), -1, squid_curtime, squid_curtime); |
3865965d AJ |
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"); | |
113 | #endif | |
114 | rep->header.putExt("Access-Control-Expose-Headers","Server"); | |
115 | } | |
8822ebee AR |
116 | entry->replaceHttpReply(rep); |
117 | } | |
118 | ||
119 | dump(entry); | |
120 | ||
121 | entry->flush(); | |
122 | ||
123 | if (atomic()) | |
124 | entry->complete(); | |
125 | } | |
f53969cc | 126 |