]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/http/RequestMethod.h
1 #ifndef SQUID_HTTPREQUESTMETHOD_H
2 #define SQUID_HTTPREQUESTMETHOD_H
4 #include "http/forward.h"
5 #include "http/MethodType.h"
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
18 class HttpRequestMethod
: public RefCountable
21 HttpRequestMethod() : theMethod(Http::METHOD_NONE
), theImage() {}
22 HttpRequestMethod(Http::MethodType
const aMethod
) : theMethod(aMethod
), theImage() {}
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.
28 \note DO NOT give end a default (ie NULL). That will cause silent char* conversion clashes.
30 HttpRequestMethod(char const * begin
, char const * end
);
32 HttpRequestMethod
& operator = (const HttpRequestMethod
& aMethod
) {
33 theMethod
= aMethod
.theMethod
;
34 theImage
= aMethod
.theImage
;
38 HttpRequestMethod
& operator = (Http::MethodType
const aMethod
) {
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
);
50 bool operator != (Http::MethodType
const & aMethod
) const { return theMethod
!= aMethod
; }
51 bool operator != (HttpRequestMethod
const & aMethod
) const {
52 return !operator==(aMethod
);
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
);
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.
70 Http::MethodType
id() const { return theMethod
; }
72 /** Get a string representation of the method. */
73 const SBuf
&image() const;
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;
79 /// Whether this method is defined as "idempotent" in HTTP/1.1
80 /// see RFC 2616 section 9.1.2
81 bool isIdempotent() const;
83 /** Whether responses to this method MAY be cached.
84 * \retval false Not cacheable.
85 * \retval true Possibly cacheable. Other details will determine.
87 bool respMaybeCacheable() const;
89 /** Whether this method SHOULD (or MUST) invalidate existing cached entries.
90 * Invalidation is always determined by the response
92 * RFC 2616 defines invalidate as either immediate purge
93 * or delayed explicit revalidate all stored copies on next use.
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.
98 bool shouldInvalidate() const;
100 /* Whether this method invalidates existing cached entries.
101 * Kept for backward-compatibility. This is the old 2.x-3.2 invalidation behaviour.
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.
108 bool purgesOthers() const;
111 Http::MethodType theMethod
; ///< Method type
112 SBuf theImage
; ///< Used for storing the Http::METHOD_OTHER only. A copy of the parsed method text.
115 inline std::ostream
&
116 operator << (std::ostream
&os
, HttpRequestMethod
const &method
)
118 os
<< method
.image();
122 #endif /* SQUID_HTTPREQUESTMETHOD_H */