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