RequestMethod.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 /* DEBUG: section 73 HTTP Request */
10 
11 #include "squid.h"
12 #include "http/RequestMethod.h"
13 #include "SquidConfig.h"
14 #include "wordlist.h"
15 
16 static Http::MethodType &
18 {
19  int tmp = (int)aMethod;
20  aMethod = (Http::MethodType)(++tmp);
21  return aMethod;
22 }
23 
30 void
32 {
33  // XXX: performance regression due to this method no longer being a constructor
34  // ensure the members are empty/default values before any of the early-return
35  // optimizations can be used.
37  theImage.clear();
38 
39  if (begin == NULL)
40  return;
41 
42  char const *end = begin + strcspn(begin, w_space);
43 
44  if (end == begin)
45  return;
46 
47  // TODO: Optimize this linear search.
49  // RFC 2616 section 5.1.1 - Method names are case-sensitive
50  // NP: this is not a HTTP_VIOLATIONS case since there is no MUST/SHOULD involved.
51  if (0 == image().caseCmp(begin, end-begin)) {
52 
53  // relaxed parser allows mixed-case and corrects them on output
55  return;
56 
57  if (0 == image().cmp(begin, end-begin))
58  return;
59  }
60  }
61 
62  // if method not found and method string is not null then it is other method
64  theImage.assign(begin, end-begin);
65 }
66 
74 {
75  if (s.isEmpty())
76  return;
77 
78  // TODO: Optimize this linear search.
80  // RFC 2616 section 5.1.1 - Method names are case-sensitive
81  // NP: this is not a HTTP_VIOLATIONS case since there is no MUST/SHOULD involved.
82  if (0 == image().caseCmp(s)) {
83 
84  // relaxed parser allows mixed-case and corrects them on output
86  return;
87 
88  if (0 == image().cmp(s))
89  return;
90  }
91  }
92 
93  // if method not found and method string is not null then it is other method
95  theImage = s;
96 }
97 
98 const SBuf &
100 {
101  static const SBuf methodOther("METHOD_OTHER");
102  if (Http::METHOD_OTHER != theMethod) {
104  } else {
105  if (!theImage.isEmpty()) {
106  return theImage;
107  } else {
108  return methodOther;
109  }
110  }
111 }
112 
113 bool
115 {
116  // Only a few methods are defined as safe. All others are "unsafe"
117 
118  // NOTE:
119  // All known RFCs which register methods are listed in comments.
120  // if there is one not listed which defines methods, it needs
121  // checking and adding. If only to say it is known to define none.
122 
123  switch (theMethod) {
124  // RFC 2068 - none
125 
126  // RFC 2616 section 9.1.1
127  case Http::METHOD_GET:
128  case Http::METHOD_HEAD:
130 
131  // RFC 3253 section 3.6
132  case Http::METHOD_REPORT:
133 
134  // RFC 3648 - none
135  // RFC 3744 - none
136  // RFC 4437 - none
137  // RFC 4791 - none
138 
139  // RFC 4918 section 9.1
141 
142  // RFC 5323 section 2
143  case Http::METHOD_SEARCH:
144 
145  // RFC 5789 - none
146  // RFC 5842 - none
147 
148  // RFC 7540 section 11.6
149  case Http::METHOD_PRI:
150 
151  return true;
152 
153  default:
154  return false;
155  }
156 }
157 
158 bool
160 {
161  // Only a few methods are defined as idempotent.
162 
163  // NOTE:
164  // All known RFCs which register methods are listed in comments.
165  // if there is one not listed which defines methods, it needs
166  // checking and adding. If only to say it is known to define none.
167 
168  switch (theMethod) {
169  // RFC 2068 - TODO check LINK/UNLINK definition
170 
171  // RFC 2616 section 9.1.2
172  case Http::METHOD_GET:
173  case Http::METHOD_HEAD:
174  case Http::METHOD_PUT:
175  case Http::METHOD_DELETE:
177  case Http::METHOD_TRACE:
178 
179  // RFC 3253 - TODO check
180  // RFC 3648 - TODO check
181  // RFC 3744 - TODO check
182  // RFC 4437 - TODO check
183  // RFC 4791 - TODO check
184 
185  // RFC 4918 section 9
188  case Http::METHOD_MKCOL:
189  case Http::METHOD_COPY:
190  case Http::METHOD_MOVE:
191  case Http::METHOD_UNLOCK:
192 
193  // RFC 5323 - TODO check
194  // RFC 5789 - TODO check
195  // RFC 5842 - TODO check
196 
197  // RFC 7540 section 11.6
198  case Http::METHOD_PRI:
199 
200  return true;
201 
202  default:
203  return false;
204  }
205 }
206 
207 bool
209 {
210  // Only a few methods are defined as cacheable.
211  // All other methods from the below RFC are "MUST NOT cache"
212  switch (theMethod) {
213  // RFC 2616 section 9
214  case Http::METHOD_GET:
215  case Http::METHOD_HEAD:
216  return true;
217 #if WHEN_POST_CACHE_SUPPORTED
218  case Http::METHOD_POST: // Special case.
219  // RFC 2616 specifies POST as possibly cacheable
220  // However, Squid does not implement the required checks yet
221  return true;
222 #endif
223 
224  // RFC 4918 section 9
225 #if WHEN_PROPFIND_CACHE_SUPPORTED
226  case Http::METHOD_PROPFIND: // Special case.
227  // RFC 4918 specifies PROPFIND as possibly cacheable
228  // However, Squid does not implement the required checks yet
229  return true;
230 #endif
231 
232  // RFC 5323 section 2 - defines no cacheable methods
233 
234  // RFC 3253
235 #if WHEN_CC_NOCACHE_DOES_REVALIDATES_IS_CONFIRMED
241  case Http::METHOD_UPDATE:
242  case Http::METHOD_LABEL:
243  case Http::METHOD_MERGE:
246  // RFC 3253 defines these methods using "MUST include Cache-Control: no-cache".
247  //
248  // XXX: follow RFC 2616 definition of "no-cache" meaning "MAY cache, always revalidate"
249  // XXX: or treat as unregistered/undefined methods ??
250  // However, Squid may not implement the required revalidation checks yet
251  return ??;
252 #endif
253 
254  // Special Squid method tokens are not cacheable.
255  // RFC 2616 defines all unregistered or unspecified methods as non-cacheable
256  // until such time as an RFC defines them cacheable.
257  default:
258  return false;
259  }
260 }
261 
262 bool
264 {
265  switch (theMethod) {
266  /* RFC 2616 section 13.10 - "MUST invalidate" */
267  case Http::METHOD_POST:
268  case Http::METHOD_PUT:
269  case Http::METHOD_DELETE:
270  return true;
271 
272  /* Squid extension to force invalidation */
273  case Http::METHOD_PURGE:
274  return true;
275 
276  /*
277  * RFC 2616 sayeth, in section 13.10, final paragraph:
278  * A cache that passes through requests for methods it does not
279  * understand SHOULD invalidate any entities referred to by the
280  * Request-URI.
281  */
282  case Http::METHOD_OTHER:
283  return true;
284 
285  default:
286  // Methods which are known but not required to invalidate.
287  return false;
288  }
289 }
290 
291 bool
293 {
294  if (shouldInvalidate())
295  return true;
296 
297  switch (theMethod) {
298  /* common sense suggests purging is not required? */
299  case Http::METHOD_GET: // XXX: but we do purge HEAD on successful GET
300  case Http::METHOD_HEAD:
301  case Http::METHOD_NONE:
303  case Http::METHOD_TRACE:
306  case Http::METHOD_COPY:
307  case Http::METHOD_LOCK:
308  case Http::METHOD_UNLOCK:
309  case Http::METHOD_SEARCH:
310  return false;
311 
312  default:
313  return true;
314  }
315 }
316 
SBuf theImage
Used for storing the Http::METHOD_OTHER only. A copy of the parsed method text.
int caseCmp(const SBuf &S, const size_type n) const
shorthand version for case-insensitive compare()
Definition: SBuf.h:273
static Http::MethodType & operator++(Http::MethodType &aMethod)
SBuf & assign(const SBuf &S)
Definition: SBuf.cc:94
Definition: SBuf.h:87
void clear()
Definition: SBuf.cc:190
bool isEmpty() const
Definition: SBuf.h:422
#define w_space
bool shouldInvalidate() const
Http::MethodType theMethod
Method type.
int relaxed_header_parser
Definition: SquidConfig.h:315
enum Http::_method_t MethodType
const SBuf MethodType_sb[]
bool isHttpSafe() const
struct SquidConfig::@112 onoff
bool SIGHDLR int STUB void int
Definition: stub_tools.cc:68
const SBuf & image() const
void HttpRequestMethodXXX(char const *)
bool respMaybeCacheable() const
int cmp(const SBuf &S, const size_type n) const
shorthand version for compare()
Definition: SBuf.h:265
class SquidConfig Config
Definition: SquidConfig.cc:12
#define NULL
Definition: types.h:166
bool purgesOthers() const
bool isIdempotent() const

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors