]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added HttpRequest::clone, completing HttpMsg::clone API. When ICAP is
authorAlex Rousskov <rousskov@measurement-factory.com>
Tue, 30 Sep 2008 16:59:13 +0000 (10:59 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Tue, 30 Sep 2008 16:59:13 +0000 (10:59 -0600)
converted to use this, it should work faster for a common "no modifications"
case because it would not have to print and parse the headers.

TODO: Consider renaming the method since it does not produce an exact,
true replica. Some connection-related flags and peer settings are not
cloned because the clone is not always "attached" or "coming from"
the same connection (e.g., it is cloned for eCAP to modify). We may also
#ifdef the method if it is not needed outside of adaptation code.

The HttpMsg::body_pipe field is now copied when a message is cloned.
I was not sure what the right thing to do there is. The field itself
may be misplaced (it is not about the message structure or properties,
but about the current body transfer state, but we lack a good place to
store that...).  To reduce the number of cloning exceptions, and since
eCAP and probably ICAP code benefit from pipe copying, it is copied
for now. It would not be too hard to change.

src/HttpMsg.h
src/HttpReply.cc
src/HttpRequest.cc
src/HttpRequest.h

index 842333bc08e9ebfcfd9dad1eaacc761b542abf4f..7ecb1ed0f9a55fa354e74673b9c1b34e0aed6b19 100644 (file)
@@ -55,6 +55,9 @@ public:
     virtual HttpMsg *_lock();  // please use HTTPMSGLOCK()
     virtual void _unlock();    // please use HTTPMSGUNLOCK()
 
+       ///< produce a message copy, except for a few connection-specific settings
+       virtual HttpMsg *clone() const = 0; ///< \todo rename: not a true copy?
+
 public:
     HttpVersion http_ver;
 
index 97e327313b1da870ffbab552a9d1362c4285e6a1..bfbd0b06fe709602d2cb7e6b7efdd5fdd851e3a5 100644 (file)
@@ -552,6 +552,7 @@ HttpReply::calcMaxBodySize(HttpRequest& request)
     }
 }
 
+// XXX: check that this is sufficient for eCAP cloning
 HttpReply *
 HttpReply::clone() const
 {
@@ -561,6 +562,8 @@ HttpReply::clone() const
     rep->hdr_sz = hdr_sz;
     rep->http_ver = http_ver;
     rep->pstate = pstate;
+    rep->body_pipe = body_pipe;
+
     rep->protocol = protocol;
     rep->sline = sline;
     return rep;
index f099d6919f7c52f8851fe08949b473bc7d3e82d4..3f17df12ec53dbb26f31fb993458ee045aa59cf8 100644 (file)
@@ -143,6 +143,59 @@ HttpRequest::reset()
     init();
 }
 
+HttpRequest *
+HttpRequest::clone() const
+{
+    HttpRequest *copy = new HttpRequest(method, protocol, urlpath.buf());
+    // TODO: move common cloning clone to Msg::copyTo() or copy ctor
+    copy->header.append(&header);
+    copy->hdrCacheInit();
+    copy->hdr_sz = hdr_sz;
+    copy->http_ver = http_ver;
+    copy->pstate = pstate; // TODO: should we assert a specific state here?
+    copy->body_pipe = body_pipe;
+
+    strncpy(copy->login, login, sizeof(login)); // MAX_LOGIN_SZ
+    strncpy(copy->host, host, sizeof(host)); // SQUIDHOSTNAMELEN
+    copy->host_addr = host_addr;
+
+    if (auth_user_request) {
+        copy->auth_user_request = auth_user_request;
+        AUTHUSERREQUESTLOCK(copy->auth_user_request, "HttpRequest::clone");
+       }
+
+    copy->port = port;
+    // urlPath handled in ctor
+       copy->canonical = canonical ? xstrdup(canonical) : NULL;
+    
+    // This may be too conservative for the 204 No Content case
+    // may eventually need cloneNullAdaptationImmune() for that.
+    copy->flags = flags.cloneAdaptationImmune();
+
+       copy->range = range ? new HttpHdrRange(*range) : NULL;
+       copy->ims = ims;
+       copy->imslen = imslen;
+       copy->max_forwards = max_forwards;
+    copy->client_addr = client_addr;
+    copy->my_addr = my_addr;
+    copy->hier = hier; // Is it safe to copy? Should we?
+
+    copy->errType = errType;
+
+    // XXX: what to do with copy->peer_login?
+
+       copy->lastmod = lastmod;
+    copy->vary_headers = vary_headers ? xstrdup(vary_headers) : NULL;
+    // XXX: what to do with copy->peer_domain?
+
+    copy->tag = tag;
+    copy->extacl_user = extacl_user;
+    copy->extacl_passwd = extacl_passwd;
+    copy->extacl_log = extacl_log;
+
+    return copy;
+}
+
 bool
 HttpRequest::sanityCheckStartLine(MemBuf *buf, http_status *error)
 {
index 39a0694dc56b03f63dbde846eda227774441afc3..2dcec900a3fd9ea86fe30a96839113a5818f07a3 100644 (file)
@@ -65,6 +65,8 @@ public:
 
     void initHTTP(const HttpRequestMethod& aMethod, protocol_t aProtocol, const char *aUrlpath);
 
+    virtual HttpRequest *clone() const;
+
     /* are responses to this request potentially cachable */
     bool cacheable() const;