]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | /* | |
3 | * $Id$ | |
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 | ||
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 | }; | |
74 | ||
75 | static | |
76 | _method_t &operator++ (_method_t &aMethod) | |
77 | { | |
78 | int tmp = (int)aMethod; | |
79 | aMethod = (_method_t)(++tmp); | |
80 | return aMethod; | |
81 | } | |
82 | ||
83 | /* | |
84 | * Construct a HttpRequestMethod from a NULL terminated string such as "GET" | |
85 | * or from a range of chars, * such as "GET" from "GETFOOBARBAZ" | |
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); | |
109 | ||
110 | if (end == begin) { | |
111 | theMethod = METHOD_NONE; | |
112 | return; | |
113 | } | |
114 | ||
115 | for (++theMethod; theMethod < METHOD_ENUM_END; ++theMethod) { | |
116 | if (0 == strncasecmp(begin, RequestMethodStr[theMethod], end-begin)) { | |
117 | return; | |
118 | } | |
119 | } | |
120 | ||
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); | |
124 | } | |
125 | ||
126 | /** \todo AYJ: this _should_ be obsolete. Since all such methods fit nicely into METHOD_OTHER now. */ | |
127 | void | |
128 | HttpRequestMethod::AddExtension(const char *mstr) | |
129 | { | |
130 | #if 0 /* obsolete now that we have METHOD_OTHER always enabled */ | |
131 | _method_t method = METHOD_NONE; | |
132 | ||
133 | for (++method; method < METHOD_ENUM_END; ++method) { | |
134 | if (0 == strcmp(mstr, RequestMethodStr[method])) { | |
135 | debugs(23, 2, "Extension method '" << mstr << "' already exists"); | |
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 | ||
145 | debugs(23, 1, "Extension method '" << mstr << "' added, enum=" << method); | |
146 | ||
147 | return; | |
148 | } | |
149 | ||
150 | debugs(23, 1, "WARNING: Could not add new extension method '" << mstr << "' due to lack of array space"); | |
151 | #endif | |
152 | } | |
153 | ||
154 | void | |
155 | HttpRequestMethod::Configure(SquidConfig &Config) | |
156 | { | |
157 | #if 0 /* extension methods obsolete now that we have METHOD_OTHER always enabled */ | |
158 | wordlist *w = Config.ext_methods; | |
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 | } | |
170 | #endif | |
171 | } | |
172 | ||
173 | char const* | |
174 | HttpRequestMethod::image() const | |
175 | { | |
176 | if (METHOD_OTHER != theMethod) { | |
177 | return RequestMethodStr[theMethod]; | |
178 | } else { | |
179 | if (theImage.size()>0) { | |
180 | return theImage.buf(); | |
181 | } else { | |
182 | return "METHOD_OTHER"; | |
183 | } | |
184 | } | |
185 | } | |
186 | ||
187 | bool | |
188 | HttpRequestMethod::isCacheble() const | |
189 | { | |
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 | ||
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; | |
205 | ||
206 | if (theMethod == METHOD_OTHER) | |
207 | return false; | |
208 | ||
209 | return true; | |
210 | } | |
211 | ||
212 | bool | |
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? */ | |
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; | |
233 | ||
234 | /* purging mandated by RFC 2616 */ | |
235 | case METHOD_POST: | |
236 | case METHOD_PUT: | |
237 | case METHOD_DELETE: | |
238 | return true; | |
239 | ||
240 | /* purging suggested by common sense */ | |
241 | case METHOD_PURGE: | |
242 | return true; | |
243 | ||
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 | */ | |
250 | case METHOD_OTHER: | |
251 | default: | |
252 | return true; | |
253 | } | |
254 | ||
255 | return true; // not reached, but just in case | |
256 | } |