]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixes many Unit-test compile errors and testing problems in HttpRequestMethod
authoramosjeffries <>
Sun, 3 Feb 2008 17:00:29 +0000 (17:00 +0000)
committeramosjeffries <>
Sun, 3 Feb 2008 17:00:29 +0000 (17:00 +0000)
- 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.

16 files changed:
src/ACLMethodData.cc
src/HttpReply.cc
src/HttpRequest.cc
src/HttpRequestMethod.cc
src/HttpRequestMethod.h
src/client_side.cc
src/client_side_reply.cc
src/client_side_request.cc
src/forward.cc
src/htcp.cc
src/http.cc
src/store_key_md5.cc
src/tests/testHttpRequest.cc
src/tests/testHttpRequestMethod.cc
src/tests/testHttpRequestMethod.h
src/url.cc

index 5999538448e27021c981593bc34e98c4f99d3185..ba97670cc97baa4e7a907419455bdeaf01240954 100644 (file)
@@ -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<HttpRequestMethod> *q = new List<HttpRequestMethod> (HttpRequestMethod(t));
+        List<HttpRequestMethod> *q = new List<HttpRequestMethod> (HttpRequestMethod(t, NULL));
         *(Tail) = q;
         Tail = &q->next;
     }
index 40aee3e644e5ac7b861d90466ca2f5bdf247af80..e5ae153bec45b2ce2dcd617c10f8a4f5e4ac99b8 100644 (file)
@@ -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 */
index 36f878ecd9cbdacb8713507e89d31dc46a5c7dd0..0acd6de5c23818565f8559f8251345a2dc9e9400 100644 (file)
@@ -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);
index aa3f41c17e107f59d4ede2a5994f338fda1cb190..208e41369f64deab51c66be608e0ad01a2340408 100644 (file)
@@ -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 
index 4c7816b12565fcffb6b802cca23e9c15a2946105..57bd3517d89cc0d4eff757255e5017af669b7cf9 100644 (file)
@@ -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)
index a0824505411f398df546e78dc9d16f9cafae365e..cbe25d1e059cb73c62da9a8395d336809738b0f2 100644 (file)
@@ -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:
 
index 0ad99b60fdf455d13af15281ba54d80b131152f1..ed9dd75e580d248d9db88d072042671c2fc0a519 100644 (file)
@@ -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();
     }
index 16782ab2db6e8abe8d77964bddf1a9a1afb9a970..cf9b3656fb14eb68a8fb1409d8878374783001c3 100644 (file)
@@ -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<HttpReply*>(msg)) {
         debugs(85,3,HERE << "REQMOD reply is HTTP reply");
 
index f29a615b3f6ed9583d01be2711e25e42ced6ba01..eaf9d00ef740faaa097358fb5362fdd065466da6 100644 (file)
@@ -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:
 
index df63c4a4a95ed05581b5141ad09dafba593882ce..81c9a251b370214f7a7ff93c780661e49a80c634 100644 (file)
@@ -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);
 
index e8c91f002e1a8e65a10dd50d0f9fc5bb94922804..88ab0ffa93c5669bed5dfb3ccfd897ab34c210ac 100644 (file)
@@ -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
          */
 
index d60c8f87042509ebb6af22ad47416f7fc156ca85..0c3330617780f66674c0cc416b0472c61098f540 100644 (file)
@@ -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);
index d0864a0e8b3f1404e63f44474d4629d7719a4981..4633bf26b2c2e911d72f508163ba762cd179c960 100644 (file)
@@ -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()));
index d5c73b1856ce25a26ee0713e2763e7fc42f48394..a24d47c091b6118deab49dcf72a2a182ff1d5e3b 100644 (file)
@@ -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()));
 }
index 8e79993d31f0ba97c75f92dc6bd78496b2a45ba0..112e32bccc47ac5dfd754e7cde16fd01af460bdd 100644 (file)
@@ -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();
index 8cfdf4dbaa192350737ca64f71def10d47b2dc9e..a56e31abcfb62b23302eed91df0086667556b2e5 100644 (file)
@@ -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",