]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpRequestMethod.cc
ext_lm_group_acl: Add missing rfc1738.h include
[thirdparty/squid.git] / src / HttpRequestMethod.cc
CommitLineData
985c86bc 1
2/*
985c86bc 3 * DEBUG: section 73 HTTP Request
4 * AUTHOR: Duane Wessels
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
26ac0430 22 *
985c86bc 23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
26ac0430 27 *
985c86bc 28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
33 */
34
582c2af2 35#include "squid.h"
985c86bc 36#include "HttpRequestMethod.h"
37#include "wordlist.h"
38
26ac0430
AJ
39const char* HttpRequestMethod::RequestMethodStr[] = {
40 "NONE",
41 "GET",
42 "POST",
43 "PUT",
44 "HEAD",
45 "CONNECT",
46 "TRACE",
47 "PURGE",
48 "OPTIONS",
49 "DELETE",
50 "PROPFIND",
51 "PROPPATCH",
52 "MKCOL",
53 "COPY",
54 "MOVE",
55 "LOCK",
56 "UNLOCK",
57 "BMOVE",
58 "BDELETE",
59 "BPROPFIND",
60 "BPROPPATCH",
61 "BCOPY",
62 "SEARCH",
63 "SUBSCRIBE",
64 "UNSUBSCRIBE",
65 "POLL",
66 "REPORT",
67 "MKACTIVITY",
68 "CHECKOUT",
69 "MERGE",
70 "ERROR"
71};
985c86bc 72
73static
60745f24 74_method_t &operator++ (_method_t &aMethod)
985c86bc 75{
76 int tmp = (int)aMethod;
60745f24 77 aMethod = (_method_t)(++tmp);
985c86bc 78 return aMethod;
79}
80
81/*
82 * Construct a HttpRequestMethod from a NULL terminated string such as "GET"
26ac0430 83 * or from a range of chars, * such as "GET" from "GETFOOBARBAZ"
985c86bc 84 * (pass in pointer to G and pointer to F.)
85 */
86HttpRequestMethod::HttpRequestMethod(char const *begin, char const *end) : theMethod (METHOD_NONE)
87{
88 if (begin == NULL)
89 return;
90
91 /*
92 * This check for '%' makes sure that we don't
93 * match one of the extension method placeholders,
94 * which have the form %EXT[0-9][0-9]
95 */
96
97 if (*begin == '%')
98 return;
99
100 /*
101 * if e is NULL, b must be NULL terminated and we
102 * make e point to the first whitespace character
103 * after b.
104 */
105 if (NULL == end)
106 end = begin + strcspn(begin, w_space);
26ac0430 107
60745f24 108 if (end == begin) {
26ac0430
AJ
109 theMethod = METHOD_NONE;
110 return;
60745f24 111 }
26ac0430 112
985c86bc 113 for (++theMethod; theMethod < METHOD_ENUM_END; ++theMethod) {
60745f24 114 if (0 == strncasecmp(begin, RequestMethodStr[theMethod], end-begin)) {
985c86bc 115 return;
60745f24 116 }
985c86bc 117 }
118
60745f24 119 // if method not found and method string is not null then it is other method
120 theMethod = METHOD_OTHER;
121 theImage.limitInit(begin,end-begin);
985c86bc 122}
123
914b89a2 124/** \todo AYJ: this _should_ be obsolete. Since all such methods fit nicely into METHOD_OTHER now. */
985c86bc 125void
126HttpRequestMethod::AddExtension(const char *mstr)
127{
c255af72 128#if 0 /* obsolete now that we have METHOD_OTHER always enabled */
60745f24 129 _method_t method = METHOD_NONE;
985c86bc 130
131 for (++method; method < METHOD_ENUM_END; ++method) {
132 if (0 == strcmp(mstr, RequestMethodStr[method])) {
bf8fe701 133 debugs(23, 2, "Extension method '" << mstr << "' already exists");
985c86bc 134 return;
135 }
136
137 if (0 != strncmp("%EXT", RequestMethodStr[method], 4))
138 continue;
139
140 /* Don't free statically allocated "%EXTnn" string */
141 RequestMethodStr[method] = xstrdup(mstr);
142
e0236918 143 debugs(23, DBG_IMPORTANT, "Extension method '" << mstr << "' added, enum=" << method);
985c86bc 144
145 return;
146 }
147
e0236918 148 debugs(23, DBG_IMPORTANT, "WARNING: Could not add new extension method '" << mstr << "' due to lack of array space");
c255af72 149#endif
985c86bc 150}
151
152void
076df709 153HttpRequestMethod::Configure(SquidConfig &cfg)
985c86bc 154{
c255af72 155#if 0 /* extension methods obsolete now that we have METHOD_OTHER always enabled */
076df709 156 wordlist *w = cfg.ext_methods;
985c86bc 157
158 while (w) {
159 char *s;
160
95dc7ff4 161 for (s = w->key; *s; ++s)
985c86bc 162 *s = xtoupper(*s);
163
164 AddExtension(w->key);
165
166 w = w->next;
167 }
c255af72 168#endif
985c86bc 169}
60745f24 170
26ac0430 171char const*
914b89a2 172HttpRequestMethod::image() const
173{
174 if (METHOD_OTHER != theMethod) {
175 return RequestMethodStr[theMethod];
26ac0430 176 } else {
914b89a2 177 if (theImage.size()>0) {
b4f2886c 178 return theImage.termedBuf();
914b89a2 179 } else {
180 return "METHOD_OTHER";
181 }
182 }
60745f24 183}
184
26ac0430 185bool
60745f24 186HttpRequestMethod::isCacheble() const
187{
c1520b67
AJ
188 // TODO: optimize the lookup with a precomputed flags array
189 // XXX: the list seems wrong; e.g., Is METHOD_DELETE really cachable?
190 // see also http.cc::httpCachable()
191
60745f24 192 if (theMethod == METHOD_CONNECT)
193 return false;
194
195 if (theMethod == METHOD_TRACE)
196 return false;
197
198 if (theMethod == METHOD_PUT)
199 return false;
200
201 if (theMethod == METHOD_POST)
202 return false;
26ac0430 203
60745f24 204 if (theMethod == METHOD_OTHER)
205 return false;
26ac0430 206
60745f24 207 return true;
208}
c1520b67 209
26ac0430 210bool
c1520b67
AJ
211HttpRequestMethod::purgesOthers() const
212{
213 // TODO: optimize the lookup with a precomputed flags array
214
215 switch (theMethod) {
216 /* common sense suggests purging is not required? */
26ac0430
AJ
217 case METHOD_GET: // XXX: but we do purge HEAD on successful GET
218 case METHOD_HEAD:
219 case METHOD_NONE:
220 case METHOD_CONNECT:
221 case METHOD_TRACE:
222 case METHOD_OPTIONS:
223 case METHOD_PROPFIND:
224 case METHOD_BPROPFIND:
225 case METHOD_COPY:
226 case METHOD_BCOPY:
227 case METHOD_LOCK:
228 case METHOD_UNLOCK:
229 case METHOD_SEARCH:
230 return false;
c1520b67
AJ
231
232 /* purging mandated by RFC 2616 */
26ac0430
AJ
233 case METHOD_POST:
234 case METHOD_PUT:
235 case METHOD_DELETE:
236 return true;
c1520b67
AJ
237
238 /* purging suggested by common sense */
26ac0430
AJ
239 case METHOD_PURGE:
240 return true;
c1520b67 241
96385560
BR
242 /*
243 * RFC 2616 sayeth, in section 13.10, final paragraph:
244 * A cache that passes through requests for methods it does not
245 * understand SHOULD invalidate any entities referred to by the
246 * Request-URI.
247 */
26ac0430
AJ
248 case METHOD_OTHER:
249 default:
250 return true;
251 }
c1520b67 252
96385560 253 return true; // not reached, but just in case
c1520b67 254}