- Removes implicit conversion from HttpRequestMethod to other types.
- Adds id() accessor to retrieve an ID for known methods.
- Adds more boolean operators to class library
Also adds auto-documantation in some METHOD-related places.
/*
- * $Id: ACLMethodData.cc,v 1.10 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: ACLMethodData.cc,v 1.11 2008/02/03 10:00:29 amosjeffries Exp $
*
* DEBUG: section 28 Access Control
* AUTHOR: Duane Wessels
delete values;
}
+/// todo make this a pass-by-reference now that HTTPRequestMethods a full class?
bool
ACLMethodData::match(HttpRequestMethod toFind)
{
- return values->findAndTune (toFind);
+ return values->findAndTune(toFind);
}
/* explicit instantiation required for some systems */
;
while ((t = strtokFile())) {
- List<HttpRequestMethod> *q = new List<HttpRequestMethod> (HttpRequestMethod(t));
+ List<HttpRequestMethod> *q = new List<HttpRequestMethod> (HttpRequestMethod(t, NULL));
*(Tail) = q;
Tail = &q->next;
}
/*
- * $Id: HttpReply.cc,v 1.98 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: HttpReply.cc,v 1.99 2008/02/03 10:00:29 amosjeffries Exp $
*
* DEBUG: section 58 HTTP Reply (Response)
* AUTHOR: Alex Rousskov
{
if (sline.version.major < 1)
return -1;
- else if (METHOD_HEAD == method)
+ else if (method.id() == METHOD_HEAD)
return 0;
else if (sline.status == HTTP_OK)
(void) 0; /* common case, continue */
/*
- * $Id: HttpRequest.cc,v 1.79 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: HttpRequest.cc,v 1.80 2008/02/03 10:00:29 amosjeffries Exp $
*
* DEBUG: section 73 HTTP Request
* AUTHOR: Duane Wessels
bool
HttpRequest::sanityCheckStartLine(MemBuf *buf, http_status *error)
{
- /*
+ /**
* Just see if the request buffer starts with a known
* HTTP request method. NOTE this whole function is somewhat
* superfluous and could just go away.
+ \todo AYJ: Check for safely removing this function. We now accept 'unknown' request methods in HTTP.
*/
- if (METHOD_NONE == HttpRequestMethod(buf->content())) {
+ if (HttpRequestMethod(buf->content(),NULL) == METHOD_NONE) {
debugs(73, 3, "HttpRequest::sanityCheckStartLine: did not find HTTP request method");
return false;
}
const char *t = start + strcspn(start, w_space);
method = HttpRequestMethod(start, t);
- if (METHOD_NONE == method)
+ if (method == METHOD_NONE)
return false;
start = t + strspn(t, w_space);
/*
- * $Id: HttpRequestMethod.cc,v 1.5 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: HttpRequestMethod.cc,v 1.6 2008/02/03 10:00:29 amosjeffries Exp $
*
* DEBUG: section 73 HTTP Request
* AUTHOR: Duane Wessels
theImage.limitInit(begin,end-begin);
}
+/** \todo AYJ: this _should_ be obsolete. Since all such methods fit nicely into METHOD_OTHER now. */
void
HttpRequestMethod::AddExtension(const char *mstr)
{
}
char const*
-HttpRequestMethod::image() const
-{
- if (METHOD_OTHER != theMethod) {
- return RequestMethodStr[theMethod];
- }
- else {
- if (theImage.size()>0)
- return theImage.buf();
- else
- return "METHOD_OTHER";
- }
+HttpRequestMethod::image() const
+{
+ if (METHOD_OTHER != theMethod) {
+ return RequestMethodStr[theMethod];
+ }
+ else {
+ if (theImage.size()>0) {
+ return theImage.buf();
+ } else {
+ return "METHOD_OTHER";
+ }
+ }
}
bool
-
/*
- * $Id: HttpRequestMethod.h,v 1.7 2008/01/21 04:02:56 amosjeffries Exp $
+ * $Id: HttpRequestMethod.h,v 1.8 2008/02/03 10:00:29 amosjeffries Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
};
/* forward decls */
-
typedef struct _SquidConfig SquidConfig;
-/* This class represents an HTTP Request METHOD - i.e.
- * PUT, POST, GET etc. It has a runtime extensionf acility to allow it to
+/**
+ * This class represents an HTTP Request METHOD
+ * - i.e. PUT, POST, GET etc.
+ * It has a runtime extension facility to allow it to
* efficiently support new methods
+ \ingroup POD
*/
-
class HttpRequestMethod
{
static void AddExtension(const char *methodString);
static void Configure(SquidConfig &Config);
- HttpRequestMethod() : theMethod(METHOD_NONE) {}
+ HttpRequestMethod() : theMethod(METHOD_NONE), theImage() {}
- HttpRequestMethod(_method_t const aMethod) : theMethod(aMethod) {}
+ HttpRequestMethod(_method_t const aMethod) : theMethod(aMethod), theImage() {}
- HttpRequestMethod(char const * begin, char const * end=0);
+ /**
+ \param begin string to convert to request method.
+ \param end end of the method string (relative to begin). Use NULL if this is unknown.
+ *
+ \note DO NOT give end a default (ie NULL). That will cause silent char* conversion clashes.
+ */
+ HttpRequestMethod(char const * begin, char const * end);
- operator _method_t() const {return theMethod; }
-
HttpRequestMethod & operator = (const HttpRequestMethod& aMethod)
{
theMethod = aMethod.theMethod;
return *this;
}
- bool operator != (_method_t const & aMethod) { return theMethod != aMethod;}
- bool operator != (HttpRequestMethod const & aMethod)
- {
- return ( (theMethod != aMethod) || (theImage != aMethod.theImage) );
+ bool operator == (_method_t const & aMethod) const { return theMethod == aMethod; }
+ bool operator == (HttpRequestMethod const & aMethod) const
+ {
+ return ( (theMethod == aMethod.theMethod) || (theImage == aMethod.theImage) );
+ }
+
+ bool operator != (_method_t const & aMethod) const { return theMethod != aMethod; }
+ bool operator != (HttpRequestMethod const & aMethod) const
+ {
+ return ( (theMethod != aMethod.theMethod) || (theImage != aMethod.theImage) );
}
-
+
+ /** Iterate through the registered HTTP methods. */
HttpRequestMethod& operator++()
{
- if (METHOD_OTHER!=theMethod)
- {
- int tmp = (int)theMethod;
- _method_t tmp_m = (_method_t)(++tmp);
-
- if (METHOD_ENUM_END >= tmp_m)
- theMethod = tmp_m;
+ if(METHOD_OTHER != theMethod) {
+ int tmp = (int)theMethod;
+ _method_t tmp_m = (_method_t)(++tmp);
+
+ if (METHOD_ENUM_END >= tmp_m)
+ theMethod = tmp_m;
}
return *this;
}
+ /** Get an ID representation of the method.
+ \retval METHOD_NONE the methopd is currently unset or unknown.
+ \retval METHOD_UNKNOWN the method has been accepted but is not one of the registerd HTTP methods.
+ \retval * the method is on of the registered HTTP methods.
+ */
+ _method_t const id() const { return theMethod; }
- /* Get a char string representation of the method. */
+ /** Get a char string representation of the method. */
char const* image() const;
-
+
bool isCacheble() const;
private:
- static const char *RequestMethodStr[];
-
- _method_t theMethod; ///< Method type
- String theImage; ///< Used for store METHOD_OTHER only
-};
+ static const char *RequestMethodStr[];
+ _method_t theMethod; ///< Method type
+ String theImage; ///< Used for store METHOD_OTHER only
+};
inline std::ostream &
operator << (std::ostream &os, HttpRequestMethod const &method)
/*
- * $Id: client_side.cc,v 1.772 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: client_side.cc,v 1.773 2008/02/03 10:00:29 amosjeffries Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
static int
clientIsContentLengthValid(HttpRequest * r)
{
- switch (r->method) {
+ switch (r->method.id()) {
case METHOD_PUT:
/*
- * $Id: client_side_reply.cc,v 1.150 2008/01/22 19:53:03 rousskov Exp $
+ * $Id: client_side_reply.cc,v 1.151 2008/02/03 10:00:30 amosjeffries Exp $
*
* DEBUG: section 88 Client-side Reply Routines
* AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
purgeRequest();
return;
}
-
- if (METHOD_OTHER == r->method) {
+
+ if (r->method == METHOD_OTHER) {
// invalidate all cache entries
purgeAllCached();
}
/*
- * $Id: client_side_request.cc,v 1.101 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: client_side_request.cc,v 1.102 2008/02/03 10:00:30 amosjeffries Exp $
*
* DEBUG: section 85 Client-side Request Routines
* AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
}
}
}
-
- if (METHOD_OTHER == request->method) {
+
+ if (request->method == METHOD_OTHER) {
no_cache++;
}
xfree(uri);
uri = xstrdup(urlCanonical(request));
setLogUri(this, urlCanonicalClean(request));
- assert(request->method);
+ assert(request->method.id());
} else if (HttpReply *new_rep = dynamic_cast<HttpReply*>(msg)) {
debugs(85,3,HERE << "REQMOD reply is HTTP reply");
/*
- * $Id: forward.cc,v 1.171 2008/01/20 18:20:05 serassio Exp $
+ * $Id: forward.cc,v 1.172 2008/02/03 10:00:30 amosjeffries Exp $
*
* DEBUG: section 17 Request Forwarding
* AUTHOR: Duane Wessels
return false;
/* RFC2616 9.1 Safe and Idempotent Methods */
- switch (request->method) {
+ switch (request->method.id()) {
/* 9.1.1 Safe Methods */
case METHOD_GET:
case METHOD_HEAD:
- /* 9.1.2 Indepontent Methods */
+ /* 9.1.2 Idempotent Methods */
case METHOD_PUT:
/*
- * $Id: htcp.cc,v 1.79 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: htcp.cc,v 1.80 2008/02/03 10:00:30 amosjeffries Exp $
*
* DEBUG: section 31 Hypertext Caching Protocol
* AUTHOR: Duane Wesssels
/*
* Parse the request
*/
- method = HttpRequestMethod(s->method);
+ method = HttpRequestMethod(s->method, NULL);
s->request = HttpRequest::CreateFromUrlAndMethod(s->uri, method == METHOD_NONE ? HttpRequestMethod(METHOD_GET) : method);
/*
- * $Id: http.cc,v 1.545 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: http.cc,v 1.546 2008/02/03 10:00:30 amosjeffries Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
static void
httpMaybeRemovePublic(StoreEntry * e, http_status status)
{
-
- int remove
- = 0;
-
+ int remove = 0;
int forbidden = 0;
-
StoreEntry *pe;
if (!EBIT_TEST(e->flags, KEY_PRIVATE))
case HTTP_GONE:
case HTTP_NOT_FOUND:
-
- remove
- = 1;
+ remove = 1;
break;
*/
if (status >= 200 && status < 300)
- remove
- = 1;
+ remove = 1;
#endif
break;
}
- if (!remove
- && !forbidden)
+ if (!remove && !forbidden)
return;
assert(e->mem_obj);
pe->release();
}
- /*
+ /** \par
* Also remove any cached HEAD response in case the object has
* changed.
*/
if (forbidden)
return;
- switch (e->mem_obj->method) {
+ /// \todo AYJ: given the coment below + new behaviour of accepting METHOD_UNKNOWN, should we invert this test
+ /// removing the object unless the method is nown to be safely kept?
+ switch (e->mem_obj->method.id()) {
case METHOD_PUT:
case METHOD_BMOVE:
case METHOD_BDELETE:
- /*
- * Remove any cached GET object if it is beleived that the
+ /** \par
+ * Remove any cached GET object if it is believed that the
* object may have changed as a result of other methods
*/
/*
- * $Id: store_key_md5.cc,v 1.37 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: store_key_md5.cc,v 1.38 2008/02/03 10:00:30 amosjeffries Exp $
*
* DEBUG: section 20 Storage Manager MD5 Cache Keys
* AUTHOR: Duane Wessels
storeKeyPublic(const char *url, const HttpRequestMethod& method)
{
static cache_key digest[SQUID_MD5_DIGEST_LENGTH];
- unsigned char m = (unsigned char) method;
+ unsigned char m = (unsigned char) method.id();
SquidMD5_CTX M;
SquidMD5Init(&M);
SquidMD5Update(&M, &m, sizeof(m));
storeKeyPublicByRequestMethod(HttpRequest * request, const HttpRequestMethod& method)
{
static cache_key digest[SQUID_MD5_DIGEST_LENGTH];
- unsigned char m = (unsigned char) method;
+ unsigned char m = (unsigned char) method.id();
const char *url = urlCanonical(request);
SquidMD5_CTX M;
SquidMD5Init(&M);
expected_port = 90;
HttpRequest *nullRequest = NULL;
CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port);
- CPPUNIT_ASSERT_EQUAL(METHOD_GET, aRequest->method);
+ CPPUNIT_ASSERT(aRequest->method == METHOD_GET);
CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost()));
CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath);
CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol);
aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_PUT);
expected_port = 80;
CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port);
- CPPUNIT_ASSERT_EQUAL(METHOD_PUT, aRequest->method);
+ CPPUNIT_ASSERT(aRequest->method == METHOD_PUT);
CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost()));
CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath);
CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol);
aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_CONNECT);
expected_port = 45;
CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port);
- CPPUNIT_ASSERT_EQUAL(METHOD_CONNECT, aRequest->method);
+ CPPUNIT_ASSERT(aRequest->method == METHOD_CONNECT);
CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost()));
CPPUNIT_ASSERT_EQUAL(String(""), aRequest->urlpath);
CPPUNIT_ASSERT_EQUAL(PROTO_NONE, aRequest->protocol);
HttpRequest *aRequest = HttpRequest::CreateFromUrl(url);
expected_port = 90;
CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port);
- CPPUNIT_ASSERT_EQUAL(METHOD_GET, aRequest->method);
+ CPPUNIT_ASSERT(aRequest->method == METHOD_GET);
CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest->GetHost()));
CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath);
CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol);
aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_GET);
expected_port = 80;
CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port);
- CPPUNIT_ASSERT_EQUAL(METHOD_GET, aRequest->method);
+ CPPUNIT_ASSERT(aRequest->method == METHOD_GET);
CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost()));
CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath);
CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol);
aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_GET);
expected_port = 90;
CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port);
- CPPUNIT_ASSERT_EQUAL(METHOD_GET, aRequest->method);
+ CPPUNIT_ASSERT(aRequest->method == METHOD_GET);
CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost()));
CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath);
CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol);
aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_GET);
expected_port = 80;
CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port);
- CPPUNIT_ASSERT_EQUAL(METHOD_GET, aRequest->method);
+ CPPUNIT_ASSERT(aRequest->method == METHOD_GET);
#if USE_IPV6
/* We hasve fixed this in IPv6 build. */
CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest->GetHost()));
testHttpRequestMethod::testConstructCharStart()
{
/* parse an empty string -> METHOD_NONE */
- CPPUNIT_ASSERT(METHOD_NONE == HttpRequestMethod(NULL));
+ CPPUNIT_ASSERT(HttpRequestMethod(NULL,NULL) == METHOD_NONE);
/* parsing a literal should work */
- CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
- CPPUNIT_ASSERT(METHOD_OTHER == HttpRequestMethod("QWERTY", NULL));
+ CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL) == METHOD_GET);
+ CPPUNIT_ASSERT(HttpRequestMethod("QWERTY", NULL) == METHOD_OTHER);
}
/*
{
char const * buffer;
/* parse an empty string -> METHOD_NONE */
- CPPUNIT_ASSERT(METHOD_NONE == HttpRequestMethod(NULL, NULL));
+ CPPUNIT_ASSERT(HttpRequestMethod(NULL, NULL) == METHOD_NONE);
/* parsing a literal should work */
- CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod("GET", NULL));
+ CPPUNIT_ASSERT(HttpRequestMethod("GET", NULL) == METHOD_GET);
/* parsing with an explicit end should work */
buffer = "POSTPLUS";
- CPPUNIT_ASSERT(METHOD_POST == HttpRequestMethod(buffer, buffer + 4));
+ CPPUNIT_ASSERT(HttpRequestMethod(buffer, buffer + 4) == METHOD_POST);
}
/*
* we should be able to get a char const * version of the method.
*/
void
-testHttpRequestMethod::testConst_str()
+testHttpRequestMethod::testImage()
{
- CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post").const_str()));
+ CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL).image()));
}
/*
{
CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE) == METHOD_NONE);
CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST) == METHOD_GET));
- CPPUNIT_ASSERT(METHOD_GET == HttpRequestMethod(METHOD_GET));
- CPPUNIT_ASSERT(not (METHOD_SEARCH == HttpRequestMethod(METHOD_TRACE)));
+ CPPUNIT_ASSERT(HttpRequestMethod(METHOD_GET) == METHOD_GET);
+ CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_TRACE) == METHOD_SEARCH));
}
/*
{
CPPUNIT_ASSERT(HttpRequestMethod(METHOD_NONE) != METHOD_GET);
CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_POST) != METHOD_POST));
- CPPUNIT_ASSERT(METHOD_NONE != HttpRequestMethod(METHOD_GET));
- CPPUNIT_ASSERT(not (METHOD_SEARCH != HttpRequestMethod(METHOD_SEARCH)));
+ CPPUNIT_ASSERT(HttpRequestMethod(METHOD_GET) != METHOD_NONE);
+ CPPUNIT_ASSERT(not (HttpRequestMethod(METHOD_SEARCH) != METHOD_SEARCH));
}
/*
testHttpRequestMethod::testStream()
{
std::ostringstream buffer;
- buffer << HttpRequestMethod("get");
+ buffer << HttpRequestMethod("get",NULL);
CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer.str().c_str()));
}
CPPUNIT_TEST( testDefaultConstructor );
CPPUNIT_TEST( testEqualmethod_t );
CPPUNIT_TEST( testNotEqualmethod_t );
- CPPUNIT_TEST( testConst_str );
+ CPPUNIT_TEST( testImage );
CPPUNIT_TEST( testStream );
CPPUNIT_TEST_SUITE_END();
void testConstructmethod_t();
void testConstructCharStart();
void testConstructCharStartEnd();
- void testConst_str();
+ void testImage();
void testDefaultConstructor();
void testEqualmethod_t();
void testNotEqualmethod_t();
/*
- * $Id: url.cc,v 1.164 2008/01/20 08:54:28 amosjeffries Exp $
+ * $Id: url.cc,v 1.165 2008/02/03 10:00:30 amosjeffries Exp $
*
* DEBUG: section 23 URL Parsing
* AUTHOR: Duane Wessels
urlCanonical(HttpRequest * request)
{
LOCAL_ARRAY(char, portbuf, 32);
+/// \todo AYJ: Performance: making this a ptr and allocating when needed will be better than a write and future xstrdup().
LOCAL_ARRAY(char, urlbuf, MAX_URL);
if (request->canonical)
if (request->protocol == PROTO_URN) {
snprintf(urlbuf, MAX_URL, "urn:%s", request->urlpath.buf());
} else {
- switch (request->method) {
+/// \todo AYJ: this could use "if..else and method == METHOD_CONNECT" easier.
+ switch (request->method.id()) {
case METHOD_CONNECT:
snprintf(urlbuf, MAX_URL, "%s:%d", request->GetHost(), request->port);
return (request->canonical = xstrdup(urlbuf));
}
+/** \todo AYJ: Performance: This is an *almost* duplicate of urlCanoncical. But elides the query-string.
+ * After copying it on in the first place! Would be less code to merge the two with a flag parameter.
+ * and never copy the query-string part in the first place
+ */
char *
urlCanonicalClean(const HttpRequest * request)
{
if (request->protocol == PROTO_URN) {
snprintf(buf, MAX_URL, "urn:%s", request->urlpath.buf());
} else {
- switch (request->method) {
+/// \todo AYJ: this could use "if..else and method == METHOD_CONNECT" easier.
+ switch (request->method.id()) {
case METHOD_CONNECT:
snprintf(buf, MAX_URL, "%s:%d",