]>
Commit | Line | Data |
---|---|---|
985c86bc | 1 | |
2 | /* | |
c255af72 | 3 | * $Id: HttpRequestMethod.cc,v 1.7 2008/02/12 00:05:11 amosjeffries Exp $ |
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. | |
24 | * | |
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. | |
29 | * | |
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 | ||
37 | #include "squid.h" | |
38 | #include "HttpRequestMethod.h" | |
39 | #include "wordlist.h" | |
40 | ||
60745f24 | 41 | const char* HttpRequestMethod::RequestMethodStr[] = |
985c86bc | 42 | { |
43 | "NONE", | |
44 | "GET", | |
45 | "POST", | |
46 | "PUT", | |
47 | "HEAD", | |
48 | "CONNECT", | |
49 | "TRACE", | |
50 | "PURGE", | |
51 | "OPTIONS", | |
52 | "DELETE", | |
53 | "PROPFIND", | |
54 | "PROPPATCH", | |
55 | "MKCOL", | |
56 | "COPY", | |
57 | "MOVE", | |
58 | "LOCK", | |
59 | "UNLOCK", | |
60 | "BMOVE", | |
61 | "BDELETE", | |
62 | "BPROPFIND", | |
63 | "BPROPPATCH", | |
64 | "BCOPY", | |
65 | "SEARCH", | |
66 | "SUBSCRIBE", | |
67 | "UNSUBSCRIBE", | |
68 | "POLL", | |
69 | "REPORT", | |
dd13ffdb | 70 | "MKACTIVITY", |
71 | "CHECKOUT", | |
72 | "MERGE", | |
985c86bc | 73 | "ERROR" |
74 | }; | |
75 | ||
76 | static | |
60745f24 | 77 | _method_t &operator++ (_method_t &aMethod) |
985c86bc | 78 | { |
79 | int tmp = (int)aMethod; | |
60745f24 | 80 | aMethod = (_method_t)(++tmp); |
985c86bc | 81 | return aMethod; |
82 | } | |
83 | ||
84 | /* | |
85 | * Construct a HttpRequestMethod from a NULL terminated string such as "GET" | |
86 | * or from a range of chars, * such as "GET" from "GETFOOBARBAZ" | |
87 | * (pass in pointer to G and pointer to F.) | |
88 | */ | |
89 | HttpRequestMethod::HttpRequestMethod(char const *begin, char const *end) : theMethod (METHOD_NONE) | |
90 | { | |
91 | if (begin == NULL) | |
92 | return; | |
93 | ||
94 | /* | |
95 | * This check for '%' makes sure that we don't | |
96 | * match one of the extension method placeholders, | |
97 | * which have the form %EXT[0-9][0-9] | |
98 | */ | |
99 | ||
100 | if (*begin == '%') | |
101 | return; | |
102 | ||
103 | /* | |
104 | * if e is NULL, b must be NULL terminated and we | |
105 | * make e point to the first whitespace character | |
106 | * after b. | |
107 | */ | |
108 | if (NULL == end) | |
109 | end = begin + strcspn(begin, w_space); | |
60745f24 | 110 | |
111 | if (end == begin) { | |
112 | theMethod = METHOD_NONE; | |
113 | return; | |
114 | } | |
115 | ||
985c86bc | 116 | for (++theMethod; theMethod < METHOD_ENUM_END; ++theMethod) { |
60745f24 | 117 | if (0 == strncasecmp(begin, RequestMethodStr[theMethod], end-begin)) { |
985c86bc | 118 | return; |
60745f24 | 119 | } |
985c86bc | 120 | } |
121 | ||
60745f24 | 122 | // if method not found and method string is not null then it is other method |
123 | theMethod = METHOD_OTHER; | |
124 | theImage.limitInit(begin,end-begin); | |
985c86bc | 125 | } |
126 | ||
914b89a2 | 127 | /** \todo AYJ: this _should_ be obsolete. Since all such methods fit nicely into METHOD_OTHER now. */ |
985c86bc | 128 | void |
129 | HttpRequestMethod::AddExtension(const char *mstr) | |
130 | { | |
c255af72 | 131 | #if 0 /* obsolete now that we have METHOD_OTHER always enabled */ |
60745f24 | 132 | _method_t method = METHOD_NONE; |
985c86bc | 133 | |
134 | for (++method; method < METHOD_ENUM_END; ++method) { | |
135 | if (0 == strcmp(mstr, RequestMethodStr[method])) { | |
bf8fe701 | 136 | debugs(23, 2, "Extension method '" << mstr << "' already exists"); |
985c86bc | 137 | return; |
138 | } | |
139 | ||
140 | if (0 != strncmp("%EXT", RequestMethodStr[method], 4)) | |
141 | continue; | |
142 | ||
143 | /* Don't free statically allocated "%EXTnn" string */ | |
144 | RequestMethodStr[method] = xstrdup(mstr); | |
145 | ||
4a7a3d56 | 146 | debugs(23, 1, "Extension method '" << mstr << "' added, enum=" << method); |
985c86bc | 147 | |
148 | return; | |
149 | } | |
150 | ||
bf8fe701 | 151 | debugs(23, 1, "WARNING: Could not add new extension method '" << mstr << "' due to lack of array space"); |
c255af72 | 152 | #endif |
985c86bc | 153 | } |
154 | ||
155 | void | |
156 | HttpRequestMethod::Configure(SquidConfig &Config) | |
157 | { | |
c255af72 | 158 | #if 0 /* extension methods obsolete now that we have METHOD_OTHER always enabled */ |
985c86bc | 159 | wordlist *w = Config.ext_methods; |
160 | ||
161 | while (w) { | |
162 | char *s; | |
163 | ||
164 | for (s = w->key; *s; s++) | |
165 | *s = xtoupper(*s); | |
166 | ||
167 | AddExtension(w->key); | |
168 | ||
169 | w = w->next; | |
170 | } | |
c255af72 | 171 | #endif |
985c86bc | 172 | } |
60745f24 | 173 | |
174 | char const* | |
914b89a2 | 175 | HttpRequestMethod::image() const |
176 | { | |
177 | if (METHOD_OTHER != theMethod) { | |
178 | return RequestMethodStr[theMethod]; | |
179 | } | |
180 | else { | |
181 | if (theImage.size()>0) { | |
182 | return theImage.buf(); | |
183 | } else { | |
184 | return "METHOD_OTHER"; | |
185 | } | |
186 | } | |
60745f24 | 187 | } |
188 | ||
189 | bool | |
190 | HttpRequestMethod::isCacheble() const | |
191 | { | |
c1520b67 AJ |
192 | // TODO: optimize the lookup with a precomputed flags array |
193 | // XXX: the list seems wrong; e.g., Is METHOD_DELETE really cachable? | |
194 | // see also http.cc::httpCachable() | |
195 | ||
60745f24 | 196 | if (theMethod == METHOD_CONNECT) |
197 | return false; | |
198 | ||
199 | if (theMethod == METHOD_TRACE) | |
200 | return false; | |
201 | ||
202 | if (theMethod == METHOD_PUT) | |
203 | return false; | |
204 | ||
205 | if (theMethod == METHOD_POST) | |
206 | return false; | |
207 | ||
208 | if (theMethod == METHOD_OTHER) | |
209 | return false; | |
210 | ||
211 | return true; | |
212 | } | |
c1520b67 AJ |
213 | |
214 | bool | |
215 | HttpRequestMethod::purgesOthers() const | |
216 | { | |
217 | // TODO: optimize the lookup with a precomputed flags array | |
218 | ||
219 | switch (theMethod) { | |
220 | /* common sense suggests purging is not required? */ | |
221 | case METHOD_GET: // XXX: but we do purge HEAD on successful GET | |
222 | case METHOD_HEAD: | |
223 | case METHOD_NONE: | |
224 | case METHOD_CONNECT: | |
225 | case METHOD_TRACE: | |
226 | case METHOD_OPTIONS: | |
227 | case METHOD_PROPFIND: | |
228 | case METHOD_BPROPFIND: | |
229 | case METHOD_COPY: | |
230 | case METHOD_BCOPY: | |
231 | case METHOD_LOCK: | |
232 | case METHOD_UNLOCK: | |
233 | case METHOD_SEARCH: | |
234 | return false; | |
235 | ||
236 | /* purging mandated by RFC 2616 */ | |
237 | case METHOD_POST: | |
238 | case METHOD_PUT: | |
239 | case METHOD_DELETE: | |
240 | return true; | |
241 | ||
242 | /* purging suggested by common sense */ | |
243 | case METHOD_PURGE: | |
244 | return true; | |
245 | ||
96385560 BR |
246 | /* |
247 | * RFC 2616 sayeth, in section 13.10, final paragraph: | |
248 | * A cache that passes through requests for methods it does not | |
249 | * understand SHOULD invalidate any entities referred to by the | |
250 | * Request-URI. | |
251 | */ | |
c1520b67 AJ |
252 | case METHOD_OTHER: |
253 | default: | |
96385560 | 254 | return true; |
c1520b67 AJ |
255 | } |
256 | ||
96385560 | 257 | return true; // not reached, but just in case |
c1520b67 | 258 | } |