]> git.ipfire.org Git - thirdparty/squid.git/blame - src/http/RequestMethod.h
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / http / RequestMethod.h
CommitLineData
bbc27441 1/*
77b1029d 2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
bbc27441
AJ
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
985c86bc 9#ifndef SQUID_HTTPREQUESTMETHOD_H
10#define SQUID_HTTPREQUESTMETHOD_H
11
47ab73f9 12#include "http/forward.h"
c2a7cefd 13#include "http/MethodType.h"
65e41a45 14#include "sbuf/SBuf.h"
582c2af2 15
4d5904f7
FC
16class SquidConfig;
17
582c2af2 18#include <iosfwd>
985c86bc 19
914b89a2 20/**
21 * This class represents an HTTP Request METHOD
22 * - i.e. PUT, POST, GET etc.
23 * It has a runtime extension facility to allow it to
985c86bc 24 * efficiently support new methods
25 */
274bd5ad 26class HttpRequestMethod : public RefCountable
985c86bc 27{
985c86bc 28public:
c2a7cefd 29 HttpRequestMethod() : theMethod(Http::METHOD_NONE), theImage() {}
c2a7cefd 30 HttpRequestMethod(Http::MethodType const aMethod) : theMethod(aMethod), theImage() {}
7a4fa6a0 31 explicit HttpRequestMethod(const SBuf &);
985c86bc 32
f9688132
AJ
33 void HttpRequestMethodXXX(char const *); // deprecated old c-string to SBuf converter.
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
ec2c4acf
AR
47 /// whether the method is set/known
48 explicit operator bool() const { return theMethod != Http::METHOD_NONE; }
49
c2a7cefd 50 bool operator == (Http::MethodType const & aMethod) const { return theMethod == aMethod; }
26ac0430 51 bool operator == (HttpRequestMethod const & aMethod) const {
25c48de2 52 return theMethod == aMethod.theMethod &&
c2a7cefd 53 (theMethod != Http::METHOD_OTHER || theImage == aMethod.theImage);
914b89a2 54 }
55
c2a7cefd 56 bool operator != (Http::MethodType const & aMethod) const { return theMethod != aMethod; }
26ac0430 57 bool operator != (HttpRequestMethod const & aMethod) const {
25c48de2 58 return !operator==(aMethod);
60745f24 59 }
914b89a2 60
d3dee261 61 /** Iterate through all HTTP method IDs. */
26ac0430 62 HttpRequestMethod& operator++() {
d3dee261 63 // TODO: when this operator is used in more than one place,
64 // replace it with HttpRequestMethods::Iterator API
c2a7cefd
AJ
65 // XXX: this interface can create Http::METHOD_OTHER without an image
66 assert(theMethod < Http::METHOD_ENUM_END);
67 theMethod = (Http::MethodType)(1 + (int)theMethod);
d3dee261 68 return *this;
60745f24 69 }
70
914b89a2 71 /** Get an ID representation of the method.
c2a7cefd
AJ
72 * \retval Http::METHOD_NONE the method is unset
73 * \retval Http::METHOD_OTHER the method is not recognized and has no unique ID
74 * \retval * the method is on of the recognized HTTP methods.
914b89a2 75 */
c2a7cefd 76 Http::MethodType id() const { return theMethod; }
985c86bc 77
7f06a3d8
AJ
78 /** Get a string representation of the method. */
79 const SBuf &image() const;
914b89a2 80
c2a7cefd
AJ
81 /// Whether this method is defined as a "safe" in HTTP/1.1
82 /// see RFC 2616 section 9.1.1
83 bool isHttpSafe() const;
84
85 /// Whether this method is defined as "idempotent" in HTTP/1.1
86 /// see RFC 2616 section 9.1.2
87 bool isIdempotent() const;
88
89 /** Whether responses to this method MAY be cached.
90 * \retval false Not cacheable.
91 * \retval true Possibly cacheable. Other details will determine.
92 */
93 bool respMaybeCacheable() const;
94
95 /** Whether this method SHOULD (or MUST) invalidate existing cached entries.
96 * Invalidation is always determined by the response
97 *
98 * RFC 2616 defines invalidate as either immediate purge
99 * or delayed explicit revalidate all stored copies on next use.
100 *
101 * \retval true SHOULD invalidate. Response details can raise this to a MUST.
102 * \retval false Other details will determine. Method is not a factor.
103 */
104 bool shouldInvalidate() const;
105
106 /* Whether this method invalidates existing cached entries.
107 * Kept for backward-compatibility. This is the old 2.x-3.2 invalidation behaviour.
108 *
109 * NOTE:
110 * purgesOthers differs from shouldInvalidate() in that purgesOthers() returns
111 * true on any methods the MAY invalidate (Squid opts to do so).
112 * shouldInvalidate() only returns true on methods which SHOULD invalidate.
113 */
c1520b67 114 bool purgesOthers() const;
985c86bc 115
116private:
c2a7cefd 117 Http::MethodType theMethod; ///< Method type
7f06a3d8 118 SBuf theImage; ///< Used for storing the Http::METHOD_OTHER only. A copy of the parsed method text.
914b89a2 119};
60745f24 120
985c86bc 121inline std::ostream &
122operator << (std::ostream &os, HttpRequestMethod const &method)
123{
60745f24 124 os << method.image();
985c86bc 125 return os;
126}
127
128#endif /* SQUID_HTTPREQUESTMETHOD_H */
f53969cc 129