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