RequestMethod.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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 
9 #ifndef SQUID_SRC_HTTP_REQUESTMETHOD_H
10 #define SQUID_SRC_HTTP_REQUESTMETHOD_H
11 
12 #include "http/forward.h"
13 #include "http/MethodType.h"
14 #include "sbuf/SBuf.h"
15 
16 class SquidConfig;
17 
18 #include <iosfwd>
19 
27 {
28 public:
30  HttpRequestMethod(Http::MethodType const aMethod) : theMethod(aMethod), theImage() {}
31  explicit HttpRequestMethod(const SBuf &);
32 
33  void HttpRequestMethodXXX(char const *); // deprecated old c-string to SBuf converter.
34 
36  theMethod = aMethod;
37  theImage.clear();
38  return *this;
39  }
40 
42  explicit operator bool() const { return theMethod != Http::METHOD_NONE; }
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 
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
61  theMethod = (Http::MethodType)(1 + (int)theMethod);
62  return *this;
63  }
64 
70  Http::MethodType id() const { return theMethod; }
71 
73  const SBuf &image() const;
74 
77  bool isHttpSafe() const;
78 
81  bool isIdempotent() const;
82 
87  bool respMaybeCacheable() const;
88 
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:
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_SRC_HTTP_REQUESTMETHOD_H */
123 
@ METHOD_OTHER
Definition: MethodType.h:93
SBuf theImage
Used for storing the Http::METHOD_OTHER only. A copy of the parsed method text.
@ METHOD_ENUM_END
Definition: MethodType.h:94
bool isHttpSafe() const
Definition: SBuf.h:93
bool purgesOthers() const
const SBuf & image() const
Definition: forward.h:17
bool respMaybeCacheable() const
bool operator==(Http::MethodType const &aMethod) const
Definition: RequestMethod.h:44
bool isIdempotent() const
void clear()
Definition: SBuf.cc:175
Http::MethodType id() const
Definition: RequestMethod.h:70
Http::MethodType theMethod
Method type.
HttpRequestMethod & operator++()
Definition: RequestMethod.h:56
std::ostream & operator<<(std::ostream &os, HttpRequestMethod const &method)
#define assert(EX)
Definition: assert.h:17
void HttpRequestMethodXXX(char const *)
bool shouldInvalidate() const
the representation of the configuration. POD.
Definition: SquidConfig.h:78
enum Http::_method_t MethodType
@ METHOD_NONE
Definition: MethodType.h:22
HttpRequestMethod(Http::MethodType const aMethod)
Definition: RequestMethod.h:30
bool operator!=(Http::MethodType const &aMethod) const
Definition: RequestMethod.h:50
HttpRequestMethod & operator=(Http::MethodType const aMethod)
Definition: RequestMethod.h:35

 

Introduction

Documentation

Support

Miscellaneous