From: amosjeffries <> Date: Sun, 3 Feb 2008 17:00:29 +0000 (+0000) Subject: Fixes many Unit-test compile errors and testing problems in HttpRequestMethod X-Git-Tag: BASIC_TPROXY4~146 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=914b89a260c3ae4f0786cf282c19a516b54a0776;p=thirdparty%2Fsquid.git Fixes many Unit-test compile errors and testing problems in HttpRequestMethod - 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. --- diff --git a/src/ACLMethodData.cc b/src/ACLMethodData.cc index 5999538448..ba97670cc9 100644 --- a/src/ACLMethodData.cc +++ b/src/ACLMethodData.cc @@ -1,5 +1,5 @@ /* - * $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 @@ -54,10 +54,11 @@ ACLMethodData::~ACLMethodData() 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 */ @@ -89,7 +90,7 @@ ACLMethodData::parse() ; while ((t = strtokFile())) { - List *q = new List (HttpRequestMethod(t)); + List *q = new List (HttpRequestMethod(t, NULL)); *(Tail) = q; Tail = &q->next; } diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 40aee3e644..e5ae153bec 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -420,7 +420,7 @@ HttpReply::bodySize(const HttpRequestMethod& method) const { 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 */ diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 36f878ecd9..0acd6de5c2 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -143,13 +143,14 @@ HttpRequest::reset() 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; } @@ -163,7 +164,7 @@ HttpRequest::parseFirstLine(const char *start, const char *end) 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); diff --git a/src/HttpRequestMethod.cc b/src/HttpRequestMethod.cc index aa3f41c17e..208e41369f 100644 --- a/src/HttpRequestMethod.cc +++ b/src/HttpRequestMethod.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -144,6 +144,7 @@ HttpRequestMethod::HttpRequestMethod(char const *begin, char const *end) : theMe 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) { @@ -187,17 +188,18 @@ HttpRequestMethod::Configure(SquidConfig &Config) } 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 diff --git a/src/HttpRequestMethod.h b/src/HttpRequestMethod.h index 4c7816b125..57bd3517d8 100644 --- a/src/HttpRequestMethod.h +++ b/src/HttpRequestMethod.h @@ -1,6 +1,5 @@ - /* - * $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/ @@ -93,15 +92,16 @@ enum _method_t { }; /* 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 { @@ -109,14 +109,18 @@ public: 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; @@ -131,38 +135,49 @@ public: 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) diff --git a/src/client_side.cc b/src/client_side.cc index a082450541..cbe25d1e05 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -667,7 +667,7 @@ clientSetKeepaliveFlag(ClientHttpRequest * http) static int clientIsContentLengthValid(HttpRequest * r) { - switch (r->method) { + switch (r->method.id()) { case METHOD_PUT: diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 0ad99b60fd..ed9dd75e58 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -1,6 +1,6 @@ /* - * $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) @@ -677,8 +677,8 @@ clientReplyContext::processMiss() purgeRequest(); return; } - - if (METHOD_OTHER == r->method) { + + if (r->method == METHOD_OTHER) { // invalidate all cache entries purgeAllCached(); } diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 16782ab2db..cf9b3656fb 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -1,6 +1,6 @@ /* - * $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) @@ -656,8 +656,8 @@ clientInterpretRequestHeaders(ClientHttpRequest * http) } } } - - if (METHOD_OTHER == request->method) { + + if (request->method == METHOD_OTHER) { no_cache++; } @@ -1126,7 +1126,7 @@ ClientHttpRequest::noteIcapAnswer(HttpMsg *msg) xfree(uri); uri = xstrdup(urlCanonical(request)); setLogUri(this, urlCanonicalClean(request)); - assert(request->method); + assert(request->method.id()); } else if (HttpReply *new_rep = dynamic_cast(msg)) { debugs(85,3,HERE << "REQMOD reply is HTTP reply"); diff --git a/src/forward.cc b/src/forward.cc index f29a615b3f..eaf9d00ef7 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -464,13 +464,13 @@ FwdState::checkRetriable() 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: diff --git a/src/htcp.cc b/src/htcp.cc index df63c4a4a9..81c9a251b3 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -762,7 +762,7 @@ htcpUnpackSpecifier(char *buf, int sz) /* * 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); diff --git a/src/http.cc b/src/http.cc index e8c91f002e..88ab0ffa93 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -200,12 +200,8 @@ httpTimeout(int fd, void *data) 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)) @@ -226,9 +222,7 @@ httpMaybeRemovePublic(StoreEntry * e, http_status status) case HTTP_GONE: case HTTP_NOT_FOUND: - - remove - = 1; + remove = 1; break; @@ -255,16 +249,14 @@ httpMaybeRemovePublic(StoreEntry * e, http_status status) */ if (status >= 200 && status < 300) - remove - = 1; + remove = 1; #endif break; } - if (!remove - && !forbidden) + if (!remove && !forbidden) return; assert(e->mem_obj); @@ -279,7 +271,7 @@ httpMaybeRemovePublic(StoreEntry * e, http_status status) pe->release(); } - /* + /** \par * Also remove any cached HEAD response in case the object has * changed. */ @@ -296,7 +288,9 @@ httpMaybeRemovePublic(StoreEntry * e, http_status status) 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: @@ -311,8 +305,8 @@ httpMaybeRemovePublic(StoreEntry * e, http_status status) 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 */ diff --git a/src/store_key_md5.cc b/src/store_key_md5.cc index d60c8f8704..0c33306177 100644 --- a/src/store_key_md5.cc +++ b/src/store_key_md5.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -117,7 +117,7 @@ const cache_key * 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)); @@ -136,7 +136,7 @@ const cache_key * 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); diff --git a/src/tests/testHttpRequest.cc b/src/tests/testHttpRequest.cc index d0864a0e8b..4633bf26b2 100644 --- a/src/tests/testHttpRequest.cc +++ b/src/tests/testHttpRequest.cc @@ -36,7 +36,7 @@ testHttpRequest::testCreateFromUrlAndMethod() 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); @@ -48,7 +48,7 @@ testHttpRequest::testCreateFromUrlAndMethod() 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); @@ -65,7 +65,7 @@ testHttpRequest::testCreateFromUrlAndMethod() 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); @@ -85,7 +85,7 @@ testHttpRequest::testCreateFromUrl() 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); @@ -108,7 +108,7 @@ testHttpRequest::testIPv6HostColonBug() 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); @@ -120,7 +120,7 @@ testHttpRequest::testIPv6HostColonBug() 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); @@ -132,7 +132,7 @@ testHttpRequest::testIPv6HostColonBug() 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())); diff --git a/src/tests/testHttpRequestMethod.cc b/src/tests/testHttpRequestMethod.cc index d5c73b1856..a24d47c091 100644 --- a/src/tests/testHttpRequestMethod.cc +++ b/src/tests/testHttpRequestMethod.cc @@ -17,10 +17,10 @@ void 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); } /* @@ -31,12 +31,12 @@ testHttpRequestMethod::testConstructCharStartEnd() { 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); } /* @@ -78,9 +78,9 @@ testHttpRequestMethod::testConstructmethod_t() * 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())); } /* @@ -92,8 +92,8 @@ testHttpRequestMethod::testEqualmethod_t() { 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)); } /* @@ -104,8 +104,8 @@ testHttpRequestMethod::testNotEqualmethod_t() { 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)); } /* @@ -115,6 +115,6 @@ void testHttpRequestMethod::testStream() { std::ostringstream buffer; - buffer << HttpRequestMethod("get"); + buffer << HttpRequestMethod("get",NULL); CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer.str().c_str())); } diff --git a/src/tests/testHttpRequestMethod.h b/src/tests/testHttpRequestMethod.h index 8e79993d31..112e32bccc 100644 --- a/src/tests/testHttpRequestMethod.h +++ b/src/tests/testHttpRequestMethod.h @@ -18,7 +18,7 @@ class testHttpRequestMethod : public CPPUNIT_NS::TestFixture 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(); @@ -29,7 +29,7 @@ protected: void testConstructmethod_t(); void testConstructCharStart(); void testConstructCharStartEnd(); - void testConst_str(); + void testImage(); void testDefaultConstructor(); void testEqualmethod_t(); void testNotEqualmethod_t(); diff --git a/src/url.cc b/src/url.cc index 8cfdf4dbaa..a56e31abcf 100644 --- a/src/url.cc +++ b/src/url.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -430,6 +430,7 @@ const char * 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) @@ -438,7 +439,8 @@ urlCanonical(HttpRequest * request) 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); @@ -465,6 +467,10 @@ urlCanonical(HttpRequest * request) 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) { @@ -476,7 +482,8 @@ 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",