]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/http/RequestMethod.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 73 HTTP Request */
12 #include "http/RequestMethod.h"
13 #include "SquidConfig.h"
16 static Http::MethodType
&
17 operator++ (Http::MethodType
&aMethod
)
19 int tmp
= (int)aMethod
;
20 aMethod
= (Http::MethodType
)(++tmp
);
25 * Construct a HttpRequestMethod from a C-string such as "GET"
26 * Assumes the string is either nul-terminated or contains whitespace
28 * \deprecated use SBuf constructor instead
31 HttpRequestMethod::HttpRequestMethodXXX(char const *begin
)
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.
36 theMethod
= Http::METHOD_NONE
;
42 char const *end
= begin
+ strcspn(begin
, w_space
);
47 // TODO: Optimize this linear search.
48 for (++theMethod
; theMethod
< Http::METHOD_ENUM_END
; ++theMethod
) {
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
)) {
53 // relaxed parser allows mixed-case and corrects them on output
54 if (Config
.onoff
.relaxed_header_parser
)
57 if (0 == image().cmp(begin
, end
-begin
))
62 // if method not found and method string is not null then it is other method
63 theMethod
= Http::METHOD_OTHER
;
64 theImage
.assign(begin
, end
-begin
);
68 * Construct a HttpRequestMethod from an SBuf string such as "GET"
69 * or from a range of chars such as "FOO" from buffer "GETFOOBARBAZ"
71 * Assumes the s parameter contains only the characters representing the method name
73 HttpRequestMethod::HttpRequestMethod(const SBuf
&s
) : theMethod(Http::METHOD_NONE
)
78 // TODO: Optimize this linear search.
79 for (++theMethod
; theMethod
< Http::METHOD_ENUM_END
; ++theMethod
) {
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
)) {
84 // relaxed parser allows mixed-case and corrects them on output
85 if (Config
.onoff
.relaxed_header_parser
)
88 if (0 == image().cmp(s
))
93 // if method not found and method string is not null then it is other method
94 theMethod
= Http::METHOD_OTHER
;
99 HttpRequestMethod::image() const
101 static const SBuf
methodOther("METHOD_OTHER");
102 if (Http::METHOD_OTHER
!= theMethod
) {
103 return Http::MethodType_sb
[theMethod
];
105 if (!theImage
.isEmpty()) {
114 HttpRequestMethod::isHttpSafe() const
116 // Only a few methods are defined as safe. All others are "unsafe"
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.
126 // RFC 2616 section 9.1.1
127 case Http::METHOD_GET
:
128 case Http::METHOD_HEAD
:
129 case Http::METHOD_OPTIONS
:
131 // RFC 3253 section 3.6
132 case Http::METHOD_REPORT
:
139 // RFC 4918 section 9.1
140 case Http::METHOD_PROPFIND
:
142 // RFC 5323 section 2
143 case Http::METHOD_SEARCH
:
156 HttpRequestMethod::isIdempotent() const
158 // Only a few methods are defined as idempotent.
161 // All known RFCs which register methods are listed in comments.
162 // if there is one not listed which defines methods, it needs
163 // checking and adding. If only to say it is known to define none.
166 // RFC 2068 - TODO check LINK/UNLINK definition
168 // RFC 2616 section 9.1.2
169 case Http::METHOD_GET
:
170 case Http::METHOD_HEAD
:
171 case Http::METHOD_PUT
:
172 case Http::METHOD_DELETE
:
173 case Http::METHOD_OPTIONS
:
174 case Http::METHOD_TRACE
:
176 // RFC 3253 - TODO check
177 // RFC 3648 - TODO check
178 // RFC 3744 - TODO check
179 // RFC 4437 - TODO check
180 // RFC 4791 - TODO check
182 // RFC 4918 section 9
183 case Http::METHOD_PROPFIND
:
184 case Http::METHOD_PROPPATCH
:
185 case Http::METHOD_MKCOL
:
186 case Http::METHOD_COPY
:
187 case Http::METHOD_MOVE
:
188 case Http::METHOD_UNLOCK
:
190 // RFC 5323 - TODO check
191 // RFC 5789 - TODO check
192 // RFC 5842 - TODO check
202 HttpRequestMethod::respMaybeCacheable() const
204 // Only a few methods are defined as cacheable.
205 // All other methods from the below RFC are "MUST NOT cache"
207 // RFC 2616 section 9
208 case Http::METHOD_GET
:
209 case Http::METHOD_HEAD
:
211 #if WHEN_POST_CACHE_SUPPORTED
212 case Http::METHOD_POST
: // Special case.
213 // RFC 2616 specifies POST as possibly cacheable
214 // However, Squid does not implement the required checks yet
218 // RFC 4918 section 9
219 #if WHEN_PROPFIND_CACHE_SUPPORTED
220 case Http::METHOD_PROPFIND
: // Special case.
221 // RFC 4918 specifies PROPFIND as possibly cacheable
222 // However, Squid does not implement the required checks yet
226 // RFC 5323 section 2 - defines no cacheable methods
229 #if WHEN_CC_NOCACHE_DOES_REVALIDATES_IS_CONFIRMED
230 case Http::METHOD_CHECKOUT
:
231 case Http::METHOD_CHECKIN
:
232 case Http::METHOD_UNCHECKOUT
:
233 case Http::METHOD_MKWORKSPACE
:
234 case Http::METHOD_VERSION_CONTROL
:
235 case Http::METHOD_UPDATE
:
236 case Http::METHOD_LABEL
:
237 case Http::METHOD_MERGE
:
238 case Http::METHOD_BASELINE_CONTROL
:
239 case Http::METHOD_MKACTIVITY
:
240 // RFC 3253 defines these methods using "MUST include Cache-Control: no-cache".
242 // XXX: follow RFC 2616 definition of "no-cache" meaning "MAY cache, always revalidate"
243 // XXX: or treat as unregistered/undefined methods ??
244 // However, Squid may not implement the required revalidation checks yet
248 // Special Squid method tokens are not cacheable.
249 // RFC 2616 defines all unregistered or unspecified methods as non-cacheable
250 // until such time as an RFC defines them cacheable.
257 HttpRequestMethod::shouldInvalidate() const
260 /* RFC 2616 section 13.10 - "MUST invalidate" */
261 case Http::METHOD_POST
:
262 case Http::METHOD_PUT
:
263 case Http::METHOD_DELETE
:
266 /* Squid extension to force invalidation */
267 case Http::METHOD_PURGE
:
271 * RFC 2616 sayeth, in section 13.10, final paragraph:
272 * A cache that passes through requests for methods it does not
273 * understand SHOULD invalidate any entities referred to by the
276 case Http::METHOD_OTHER
:
280 // Methods which are known but not required to invalidate.
286 HttpRequestMethod::purgesOthers() const
288 if (shouldInvalidate())
292 /* common sense suggests purging is not required? */
293 case Http::METHOD_GET
: // XXX: but we do purge HEAD on successful GET
294 case Http::METHOD_HEAD
:
295 case Http::METHOD_NONE
:
296 case Http::METHOD_CONNECT
:
297 case Http::METHOD_TRACE
:
298 case Http::METHOD_OPTIONS
:
299 case Http::METHOD_PROPFIND
:
300 case Http::METHOD_COPY
:
301 case Http::METHOD_LOCK
:
302 case Http::METHOD_UNLOCK
:
303 case Http::METHOD_SEARCH
: