]> git.ipfire.org Git - thirdparty/squid.git/blob - src/http/RequestMethod.h
Merge fron trunk rev.13398
[thirdparty/squid.git] / src / http / RequestMethod.h
1 #ifndef SQUID_HTTPREQUESTMETHOD_H
2 #define SQUID_HTTPREQUESTMETHOD_H
3
4 #include "http/forward.h"
5 #include "http/MethodType.h"
6 #include "SBuf.h"
7
8 class SquidConfig;
9
10 #include <iosfwd>
11
12 /**
13 * This class represents an HTTP Request METHOD
14 * - i.e. PUT, POST, GET etc.
15 * It has a runtime extension facility to allow it to
16 * efficiently support new methods
17 */
18 class HttpRequestMethod : public RefCountable
19 {
20 public:
21 HttpRequestMethod() : theMethod(Http::METHOD_NONE), theImage() {}
22 HttpRequestMethod(Http::MethodType const aMethod) : theMethod(aMethod), theImage() {}
23
24 /**
25 \param begin string to convert to request method.
26 \param end end of the method string (relative to begin). Use NULL if this is unknown.
27 *
28 \note DO NOT give end a default (ie NULL). That will cause silent char* conversion clashes.
29 */
30 HttpRequestMethod(char const * begin, char const * end);
31
32 HttpRequestMethod & operator = (const HttpRequestMethod& aMethod) {
33 theMethod = aMethod.theMethod;
34 theImage = aMethod.theImage;
35 return *this;
36 }
37
38 HttpRequestMethod & operator = (Http::MethodType const aMethod) {
39 theMethod = aMethod;
40 theImage.clear();
41 return *this;
42 }
43
44 bool operator == (Http::MethodType const & aMethod) const { return theMethod == aMethod; }
45 bool operator == (HttpRequestMethod const & aMethod) const {
46 return theMethod == aMethod.theMethod &&
47 (theMethod != Http::METHOD_OTHER || theImage == aMethod.theImage);
48 }
49
50 bool operator != (Http::MethodType const & aMethod) const { return theMethod != aMethod; }
51 bool operator != (HttpRequestMethod const & aMethod) const {
52 return !operator==(aMethod);
53 }
54
55 /** Iterate through all HTTP method IDs. */
56 HttpRequestMethod& operator++() {
57 // TODO: when this operator is used in more than one place,
58 // replace it with HttpRequestMethods::Iterator API
59 // XXX: this interface can create Http::METHOD_OTHER without an image
60 assert(theMethod < Http::METHOD_ENUM_END);
61 theMethod = (Http::MethodType)(1 + (int)theMethod);
62 return *this;
63 }
64
65 /** Get an ID representation of the method.
66 * \retval Http::METHOD_NONE the method is unset
67 * \retval Http::METHOD_OTHER the method is not recognized and has no unique ID
68 * \retval * the method is on of the recognized HTTP methods.
69 */
70 Http::MethodType id() const { return theMethod; }
71
72 /** Get a string representation of the method. */
73 const SBuf &image() const;
74
75 /// Whether this method is defined as a "safe" in HTTP/1.1
76 /// see RFC 2616 section 9.1.1
77 bool isHttpSafe() const;
78
79 /// Whether this method is defined as "idempotent" in HTTP/1.1
80 /// see RFC 2616 section 9.1.2
81 bool isIdempotent() const;
82
83 /** Whether responses to this method MAY be cached.
84 * \retval false Not cacheable.
85 * \retval true Possibly cacheable. Other details will determine.
86 */
87 bool respMaybeCacheable() const;
88
89 /** Whether this method SHOULD (or MUST) invalidate existing cached entries.
90 * Invalidation is always determined by the response
91 *
92 * RFC 2616 defines invalidate as either immediate purge
93 * or delayed explicit revalidate all stored copies on next use.
94 *
95 * \retval true SHOULD invalidate. Response details can raise this to a MUST.
96 * \retval false Other details will determine. Method is not a factor.
97 */
98 bool shouldInvalidate() const;
99
100 /* Whether this method invalidates existing cached entries.
101 * Kept for backward-compatibility. This is the old 2.x-3.2 invalidation behaviour.
102 *
103 * NOTE:
104 * purgesOthers differs from shouldInvalidate() in that purgesOthers() returns
105 * true on any methods the MAY invalidate (Squid opts to do so).
106 * shouldInvalidate() only returns true on methods which SHOULD invalidate.
107 */
108 bool purgesOthers() const;
109
110 private:
111 Http::MethodType theMethod; ///< Method type
112 SBuf theImage; ///< Used for storing the Http::METHOD_OTHER only. A copy of the parsed method text.
113 };
114
115 inline std::ostream &
116 operator << (std::ostream &os, HttpRequestMethod const &method)
117 {
118 os << method.image();
119 return os;
120 }
121
122 #endif /* SQUID_HTTPREQUESTMETHOD_H */