]>
Commit | Line | Data |
---|---|---|
985c86bc | 1 | /* |
262a0e14 | 2 | * $Id$ |
985c86bc | 3 | * |
4 | * | |
5 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
6 | * ---------------------------------------------------------- | |
7 | * | |
8 | * Squid is the result of efforts by numerous individuals from | |
9 | * the Internet community; see the CONTRIBUTORS file for full | |
10 | * details. Many organizations have provided support for Squid's | |
11 | * development; see the SPONSORS file for full details. Squid is | |
12 | * Copyrighted (C) 2001 by the Regents of the University of | |
13 | * California; see the COPYRIGHT file for full details. Squid | |
14 | * incorporates software developed and/or copyrighted by other | |
15 | * sources; see the CREDITS file for full details. | |
16 | * | |
17 | * This program is free software; you can redistribute it and/or modify | |
18 | * it under the terms of the GNU General Public License as published by | |
19 | * the Free Software Foundation; either version 2 of the License, or | |
20 | * (at your option) any later version. | |
26ac0430 | 21 | * |
985c86bc | 22 | * This program is distributed in the hope that it will be useful, |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU General Public License for more details. | |
26ac0430 | 26 | * |
985c86bc | 27 | * You should have received a copy of the GNU General Public License |
28 | * along with this program; if not, write to the Free Software | |
29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
30 | * | |
31 | */ | |
32 | ||
33 | #ifndef SQUID_HTTPREQUESTMETHOD_H | |
34 | #define SQUID_HTTPREQUESTMETHOD_H | |
35 | ||
f7f3304a | 36 | #include "squid-old.h" |
985c86bc | 37 | #include <iosfwd> |
a8e2f334 | 38 | #include "SquidString.h" |
985c86bc | 39 | |
40 | enum _method_t { | |
41 | METHOD_NONE, /* 000 */ | |
42 | METHOD_GET, /* 001 */ | |
43 | METHOD_POST, /* 010 */ | |
44 | METHOD_PUT, /* 011 */ | |
45 | METHOD_HEAD, /* 100 */ | |
46 | METHOD_CONNECT, /* 101 */ | |
47 | METHOD_TRACE, /* 110 */ | |
48 | METHOD_PURGE, /* 111 */ | |
49 | METHOD_OPTIONS, | |
50 | METHOD_DELETE, /* RFC2616 section 9.7 */ | |
51 | METHOD_PROPFIND, | |
52 | METHOD_PROPPATCH, | |
53 | METHOD_MKCOL, | |
54 | METHOD_COPY, | |
55 | METHOD_MOVE, | |
56 | METHOD_LOCK, | |
57 | METHOD_UNLOCK, | |
58 | METHOD_BMOVE, | |
59 | METHOD_BDELETE, | |
60 | METHOD_BPROPFIND, | |
61 | METHOD_BPROPPATCH, | |
62 | METHOD_BCOPY, | |
63 | METHOD_SEARCH, | |
64 | METHOD_SUBSCRIBE, | |
65 | METHOD_UNSUBSCRIBE, | |
66 | METHOD_POLL, | |
67 | METHOD_REPORT, | |
dd13ffdb | 68 | METHOD_MKACTIVITY, |
69 | METHOD_CHECKOUT, | |
70 | METHOD_MERGE, | |
60745f24 | 71 | METHOD_OTHER, |
72 | METHOD_ENUM_END // MUST be last, (yuck) this is used as an array-initialization index constant! | |
985c86bc | 73 | }; |
74 | ||
985c86bc | 75 | |
914b89a2 | 76 | /** |
77 | * This class represents an HTTP Request METHOD | |
78 | * - i.e. PUT, POST, GET etc. | |
79 | * It has a runtime extension facility to allow it to | |
985c86bc | 80 | * efficiently support new methods |
914b89a2 | 81 | \ingroup POD |
985c86bc | 82 | */ |
985c86bc | 83 | class HttpRequestMethod |
84 | { | |
85 | ||
86 | public: | |
87 | static void AddExtension(const char *methodString); | |
88 | static void Configure(SquidConfig &Config); | |
89 | ||
914b89a2 | 90 | HttpRequestMethod() : theMethod(METHOD_NONE), theImage() {} |
985c86bc | 91 | |
914b89a2 | 92 | HttpRequestMethod(_method_t const aMethod) : theMethod(aMethod), theImage() {} |
985c86bc | 93 | |
914b89a2 | 94 | /** |
95 | \param begin string to convert to request method. | |
96 | \param end end of the method string (relative to begin). Use NULL if this is unknown. | |
97 | * | |
98 | \note DO NOT give end a default (ie NULL). That will cause silent char* conversion clashes. | |
99 | */ | |
100 | HttpRequestMethod(char const * begin, char const * end); | |
985c86bc | 101 | |
26ac0430 | 102 | HttpRequestMethod & operator = (const HttpRequestMethod& aMethod) { |
60745f24 | 103 | theMethod = aMethod.theMethod; |
104 | theImage = aMethod.theImage; | |
105 | return *this; | |
106 | } | |
985c86bc | 107 | |
26ac0430 | 108 | HttpRequestMethod & operator = (_method_t const aMethod) { |
985c86bc | 109 | theMethod = aMethod; |
60745f24 | 110 | theImage.clean(); |
985c86bc | 111 | return *this; |
112 | } | |
113 | ||
914b89a2 | 114 | bool operator == (_method_t const & aMethod) const { return theMethod == aMethod; } |
26ac0430 | 115 | bool operator == (HttpRequestMethod const & aMethod) const { |
25c48de2 | 116 | return theMethod == aMethod.theMethod && |
26ac0430 | 117 | (theMethod != METHOD_OTHER || theImage == aMethod.theImage); |
914b89a2 | 118 | } |
119 | ||
120 | bool operator != (_method_t const & aMethod) const { return theMethod != aMethod; } | |
26ac0430 | 121 | bool operator != (HttpRequestMethod const & aMethod) const { |
25c48de2 | 122 | return !operator==(aMethod); |
60745f24 | 123 | } |
914b89a2 | 124 | |
d3dee261 | 125 | /** Iterate through all HTTP method IDs. */ |
26ac0430 | 126 | HttpRequestMethod& operator++() { |
d3dee261 | 127 | // TODO: when this operator is used in more than one place, |
128 | // replace it with HttpRequestMethods::Iterator API | |
129 | // XXX: this interface can create METHOD_OTHER without an image | |
130 | assert(theMethod < METHOD_ENUM_END); | |
131 | theMethod = (_method_t)(1 + (int)theMethod); | |
132 | return *this; | |
60745f24 | 133 | } |
134 | ||
914b89a2 | 135 | /** Get an ID representation of the method. |
d3dee261 | 136 | \retval METHOD_NONE the method is unset |
137 | \retval METHOD_OTHER the method is not recognized and has no unique ID | |
138 | \retval * the method is on of the recognized HTTP methods. | |
914b89a2 | 139 | */ |
1dc746da | 140 | _method_t id() const { return theMethod; } |
985c86bc | 141 | |
914b89a2 | 142 | /** Get a char string representation of the method. */ |
1dc746da | 143 | char const * image() const; |
914b89a2 | 144 | |
60745f24 | 145 | bool isCacheble() const; |
c1520b67 | 146 | bool purgesOthers() const; |
985c86bc | 147 | |
148 | private: | |
914b89a2 | 149 | static const char *RequestMethodStr[]; |
985c86bc | 150 | |
914b89a2 | 151 | _method_t theMethod; ///< Method type |
152 | String theImage; ///< Used for store METHOD_OTHER only | |
153 | }; | |
60745f24 | 154 | |
985c86bc | 155 | inline std::ostream & |
156 | operator << (std::ostream &os, HttpRequestMethod const &method) | |
157 | { | |
60745f24 | 158 | os << method.image(); |
985c86bc | 159 | return os; |
160 | } | |
161 | ||
60745f24 | 162 | inline const char* |
26ac0430 | 163 | RequestMethodStr(const _method_t m) |
60745f24 | 164 | { |
26ac0430 | 165 | return HttpRequestMethod(m).image(); |
60745f24 | 166 | } |
167 | ||
168 | inline const char* | |
26ac0430 | 169 | RequestMethodStr(const HttpRequestMethod& m) |
60745f24 | 170 | { |
26ac0430 | 171 | return m.image(); |
60745f24 | 172 | } |
173 | ||
985c86bc | 174 | #endif /* SQUID_HTTPREQUESTMETHOD_H */ |