]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Henrik Nordstrom <hno@squid-cache.org>
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 6 Feb 2010 06:32:11 +0000 (19:32 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 6 Feb 2010 06:32:11 +0000 (19:32 +1300)
Clean up use of httpReplySetHeaders to be consistent across the code, and
remove the unneeded http_version argument.

Ported from 2.7

21 files changed:
src/HttpReply.cc
src/HttpReply.h
src/cache_manager.cc
src/client_side_reply.cc
src/client_side_request.cc
src/errorpage.cc
src/ftp.cc
src/gopher.cc
src/http.cc
src/icmp/net_db.cc
src/internal.cc
src/mime.cc
src/neighbors.cc
src/store.cc
src/store_digest.cc
src/tests/stub_HttpReply.cc
src/tests/testCoss.cc
src/tests/testNull.cc
src/tests/testUfs.cc
src/urn.cc
src/whois.cc

index 50af61ba54c132eeb9c4fbcd1e0ab8df822793ce..66fe3ed2a43dc64649caf2ddb7d43905f3b67f3e 100644 (file)
@@ -156,19 +156,20 @@ HttpReply::pack()
     return mb;
 }
 
+#if DEAD_CODE
 MemBuf *
-httpPackedReply(HttpVersion ver, http_status status, const char *ctype,
-                int64_t clen, time_t lmt, time_t expires)
+httpPackedReply(http_status status, const char *ctype, int64_t clen, time_t lmt, time_t expires)
 {
     HttpReply *rep = new HttpReply;
-    rep->setHeaders(ver, status, ctype, NULL, clen, lmt, expires);
+    rep->setHeaders(status, ctype, NULL, clen, lmt, expires);
     MemBuf *mb = rep->pack();
     delete rep;
     return mb;
 }
+#endif
 
 HttpReply *
-HttpReply::make304 () const
+HttpReply::make304() const
 {
     static const http_hdr_type ImsEntries[] = {HDR_DATE, HDR_CONTENT_TYPE, HDR_EXPIRES, HDR_LAST_MODIFIED, /* eof */ HDR_OTHER};
 
@@ -185,8 +186,7 @@ HttpReply::make304 () const
     /* rv->content_range */
     /* rv->keep_alive */
     HttpVersion ver(1,0);
-    httpStatusLineSet(&rv->sline, ver,
-                      HTTP_NOT_MODIFIED, "");
+    httpStatusLineSet(&rv->sline, ver, HTTP_NOT_MODIFIED, "");
 
     for (t = 0; ImsEntries[t] != HDR_OTHER; ++t)
         if ((e = header.findEntry(ImsEntries[t])))
@@ -209,10 +209,11 @@ HttpReply::packed304Reply()
 }
 
 void
-HttpReply::setHeaders(HttpVersion ver, http_status status, const char *reason,
+HttpReply::setHeaders(http_status status, const char *reason,
                       const char *ctype, int64_t clen, time_t lmt, time_t expiresTime)
 {
     HttpHeader *hdr;
+    HttpVersion ver(1,0);
     httpStatusLineSet(&sline, ver, status, reason);
     hdr = &header;
     hdr->putStr(HDR_SERVER, visible_appname_string);
index 1b0a55a1cd4d719de405fa9b44a48ff75b40b341..9bd8c46ec11a2cae40ceaf9518a63afbefe9ca56 100644 (file)
 
 extern void httpReplyInitModule(void);
 
+#if DEAD_CODE
 /** do everything in one call: init, set, pack, clean, return MemBuf */
 extern MemBuf *httpPackedReply(HttpVersion ver, http_status status, const char *ctype, int64_t clen, time_t lmt, time_t expires);
+#endif
 
 /* Sync changes here with HttpReply.cc */
 
@@ -104,7 +106,7 @@ public:
     void updateOnNotModified(HttpReply const *other);
 
     /** set commonly used info with one call */
-    void setHeaders(HttpVersion ver, http_status status,
+    void setHeaders(http_status status,
                     const char *reason, const char *ctype, int64_t clen, time_t lmt, time_t expires);
 
     /** \return a ready to use mem buffer with a packed reply */
index fec008686668527dba1086ba889a92fa26047a76..dc8310857a4072bdefa57dde3a955fa24ea44ffa 100644 (file)
@@ -337,15 +337,8 @@ CacheManager::Start(int fd, HttpRequest * request, StoreEntry * entry)
     entry->buffer();
 
     {
-        HttpVersion version(1,0);
         HttpReply *rep = new HttpReply;
-        rep->setHeaders(version,
-                        HTTP_OK,
-                        NULL,
-                        "text/plain",
-                        -1,                    /* C-Len */
-                        squid_curtime, /* LMT */
-                        squid_curtime);
+        rep->setHeaders(HTTP_OK, NULL, "text/plain", -1, squid_curtime, squid_curtime);
         entry->replaceHttpReply(rep);
     }
 
index 8d37cb327d60731a72d36da651c28c5d1e166fcf..4e7243ae7dc82dda5999ad9ba66cf6c17f47e495 100644 (file)
@@ -935,13 +935,8 @@ clientReplyContext::purgeDoPurgeHead(StoreEntry *newEntry)
     triggerInitialStoreRead();
 
     HttpReply *rep = new HttpReply;
-
-    HttpVersion version(1,0);
-
-    rep->setHeaders(version, purgeStatus, NULL, NULL, 0, 0, -1);
-
+    rep->setHeaders(purgeStatus, NULL, NULL, 0, 0, -1);
     http->storeEntry()->replaceHttpReply(rep);
-
     http->storeEntry()->complete();
 }
 
@@ -960,9 +955,7 @@ clientReplyContext::traceReply(clientStreamNode * node)
     http->storeEntry()->releaseRequest();
     http->storeEntry()->buffer();
     HttpReply *rep = new HttpReply;
-    HttpVersion version(1,0);
-    rep->setHeaders(version, HTTP_OK, NULL, "text/plain",
-                    http->request->prefixLen(), 0, squid_curtime);
+    rep->setHeaders(HTTP_OK, NULL, "text/plain", http->request->prefixLen(), 0, squid_curtime);
     http->storeEntry()->replaceHttpReply(rep);
     http->request->swapOut(http->storeEntry());
     http->storeEntry()->complete();
index 2cb7d92bb66a221432b998dc9451adfd46b4ebec..82c52557bd14a1bd212ae5ef8d61ca9063cec95f 100644 (file)
@@ -285,18 +285,21 @@ ClientHttpRequest::~ClientHttpRequest()
     PROF_stop(httpRequestFree);
 }
 
-/* Create a request and kick it off */
-/*
+/**
+ * Create a request and kick it off
+ *
+ * \retval 0     success
+ * \retval -1    failure
+ *
  * TODO: Pass in the buffers to be used in the inital Read request, as they are
  * determined by the user
  */
-int                            /* returns nonzero on failure */
+int
 clientBeginRequest(const HttpRequestMethod& method, char const *url, CSCB * streamcallback,
                    CSD * streamdetach, ClientStreamData streamdata, HttpHeader const *header,
                    char *tailbuf, size_t taillen)
 {
     size_t url_sz;
-    HttpVersion http_ver (1, 0);
     ClientHttpRequest *http = new ClientHttpRequest(NULL);
     HttpRequest *request;
     StoreIOBuffer tempBuffer;
@@ -325,7 +328,7 @@ clientBeginRequest(const HttpRequestMethod& method, char const *url, CSCB * stre
     }
 
     /*
-     * now update the headers in request with our supplied headers. urLParse
+     * now update the headers in request with our supplied headers. urlParse
      * should return a blank header set, but we use Update to be sure of
      * correctness.
      */
@@ -364,6 +367,8 @@ clientBeginRequest(const HttpRequestMethod& method, char const *url, CSCB * stre
 
     request->my_addr.SetPort(0);
 
+    /* RFC 2616 says 'upgrade' to our 1.0 regardless of what the client is */
+    HttpVersion http_ver(1,0);
     request->http_ver = http_ver;
 
     http->request = HTTPMSGLOCK(request);
index f3e6cb553bfe8c1061870d280537a2334a1b57ef..834c6587c8d2eff8221eea7ff239965cae3db45e 100644 (file)
@@ -887,11 +887,10 @@ ErrorState::BuildHttpReply()
     HttpReply *rep = new HttpReply;
     const char *name = errorPageName(page_id);
     /* no LMT for error pages; error pages expire immediately */
-    HttpVersion version(1, 0);
 
     if (strchr(name, ':')) {
         /* Redirection */
-        rep->setHeaders(version, HTTP_MOVED_TEMPORARILY, NULL, "text/html", 0, 0, -1);
+        rep->setHeaders(HTTP_MOVED_TEMPORARILY, NULL, "text/html", 0, 0, -1);
 
         if (request) {
             MemBuf redirect_location;
@@ -903,7 +902,7 @@ ErrorState::BuildHttpReply()
         httpHeaderPutStrf(&rep->header, HDR_X_SQUID_ERROR, "%d %s", httpStatus, "Access Denied");
     } else {
         MemBuf *content = BuildContent();
-        rep->setHeaders(version, httpStatus, NULL, "text/html", content->contentSize(), 0, -1);
+        rep->setHeaders(httpStatus, NULL, "text/html", content->contentSize(), 0, -1);
         /*
          * include some information for downstream caches. Implicit
          * replaceable content. This isn't quite sufficient. xerrno is not
index fe97f65403404f72a04dabec7aaccf216694e49f..6d20ba8434786e36db7d56501e1b5ee4efebab09 100644 (file)
@@ -3697,11 +3697,9 @@ FtpStateData::appendSuccessHeader()
 
     /* set standard stuff */
 
-    HttpVersion version(1, 0);
     if (0 == getCurrentOffset()) {
         /* Full reply */
-        reply->setHeaders(version, HTTP_OK, "Gatewaying",
-                          mime_type, theSize, mdtm, -2);
+        reply->setHeaders(HTTP_OK, "Gatewaying", mime_type, theSize, mdtm, -2);
     } else if (theSize < getCurrentOffset()) {
         /*
          * DPW 2007-05-04
@@ -3713,15 +3711,13 @@ FtpStateData::appendSuccessHeader()
                " current offset=" << getCurrentOffset() <<
                ", but theSize=" << theSize <<
                ".  assuming full content response");
-        reply->setHeaders(version, HTTP_OK, "Gatewaying",
-                          mime_type, theSize, mdtm, -2);
+        reply->setHeaders(HTTP_OK, "Gatewaying", mime_type, theSize, mdtm, -2);
     } else {
         /* Partial reply */
         HttpHdrRangeSpec range_spec;
         range_spec.offset = getCurrentOffset();
         range_spec.length = theSize - getCurrentOffset();
-        reply->setHeaders(version, HTTP_PARTIAL_CONTENT, "Gatewaying",
-                          mime_type, theSize - getCurrentOffset(), mdtm, -2);
+        reply->setHeaders(HTTP_PARTIAL_CONTENT, "Gatewaying", mime_type, theSize - getCurrentOffset(), mdtm, -2);
         httpHeaderAddContRange(&reply->header, range_spec, theSize);
     }
 
index 4003b705436119ddcb71bfbb2f72f9e9bd635136..293059ee46de9f449d2fcee517e3e2dc1dbb9ea3 100644 (file)
@@ -251,8 +251,7 @@ gopherMimeCreate(GopherStateData * gopherState)
 
     HttpReply *reply = new HttpReply;
     entry->buffer();
-    HttpVersion version(1, 0);
-    reply->setHeaders(version, HTTP_OK, "Gatewaying", mime_type, -1, -1, -2);
+    reply->setHeaders(HTTP_OK, "Gatewaying", mime_type, -1, -1, -2);
     if (mime_enc)
         reply->header.putStr(HDR_CONTENT_ENCODING, mime_enc);
 
index 1d7c99daaf5bc210d1e2d998ce390fcc4994948a..22d9014116bd6e238a9e4e0f370ae04f48169c48 100644 (file)
@@ -685,9 +685,7 @@ HttpStateData::processReplyHeader()
     if (!parsed && readBuf->contentSize() > 5 && strncmp(readBuf->content(), "HTTP/", 5) != 0 && strncmp(readBuf->content(), "ICY", 3) != 0) {
         MemBuf *mb;
         HttpReply *tmprep = new HttpReply;
-        tmprep->sline.version = HttpVersion(1, 0);
-        tmprep->sline.status = HTTP_OK;
-        tmprep->header.putTime(HDR_DATE, squid_curtime);
+        tmprep->setHeaders(HTTP_OK, "Gatewaying", NULL, -1, -1, -1);
         tmprep->header.putExt("X-Transformed-From", "HTTP/0.9");
         mb = tmprep->pack();
         newrep->parse(mb, eof, &error);
@@ -696,7 +694,7 @@ HttpStateData::processReplyHeader()
         if (!parsed && error > 0) { // unrecoverable parsing error
             debugs(11, 3, "processReplyHeader: Non-HTTP-compliant header: '" <<  readBuf->content() << "'");
             flags.headers_parsed = 1;
-            newrep->sline.version = HttpVersion(1, 0);
+            newrep->sline.version = HttpVersion(1,0);
             newrep->sline.status = error;
             HttpReply *vrep = setVirginReply(newrep);
             entry->replaceHttpReply(vrep);
@@ -1926,7 +1924,7 @@ HttpStateData::buildRequestPrefix(HttpRequest * aRequest,
                                   http_state_flags stateFlags)
 {
     const int offset = mb->size;
-    HttpVersion httpver(1, 0);
+    HttpVersion httpver(1,0);
     mb->Printf("%s %s HTTP/%d.%d\r\n",
                RequestMethodStr(aRequest->method),
                aRequest->urlpath.size() ? aRequest->urlpath.termedBuf() : "/",
index 66f8d3ff04d9a5dcd803c4885e6ab43f557750c4..32df89cdc10bc0942001c240f188130c138c3409 100644 (file)
@@ -1223,8 +1223,7 @@ netdbBinaryExchange(StoreEntry * s)
 
     struct in_addr line_addr;
     s->buffer();
-    HttpVersion version(1, 0);
-    reply->setHeaders(version, HTTP_OK, "OK", NULL, -1, squid_curtime, -2);
+    reply->setHeaders(HTTP_OK, "OK", NULL, -1, squid_curtime, -2);
     s->replaceHttpReply(reply);
     rec_sz = 0;
     rec_sz += 1 + sizeof(struct in_addr);
@@ -1287,9 +1286,7 @@ netdbBinaryExchange(StoreEntry * s)
     memFree(buf, MEM_4K_BUF);
 #else
 
-    HttpVersion version(1,0);
-    reply->setHeaders(version, HTTP_BAD_REQUEST, "Bad Request",
-                      NULL, -1, squid_curtime, -2);
+    reply->setHeaders(HTTP_BAD_REQUEST, "Bad Request", NULL, -1, squid_curtime, -2);
     s->replaceHttpReply(reply);
     storeAppendPrintf(s, "NETDB support not compiled into this Squid cache.\n");
 #endif
index 51d20d80bd0a2d5d4165530d9c6dbd08eb127b2b..b152feccfb1bf56d868547f9fd9cf14394d2e73f 100644 (file)
@@ -64,15 +64,8 @@ internalStart(HttpRequest * request, StoreEntry * entry)
         const char *msgbuf = "This cache does not support Cache Digests.\n";
 #endif
 
-        HttpVersion version(1, 0);
         HttpReply *reply = new HttpReply;
-        reply->setHeaders(version,
-                          HTTP_NOT_FOUND,
-                          "Not Found",
-                          "text/plain",
-                          strlen(msgbuf),
-                          squid_curtime,
-                          -2);
+        reply->setHeaders(HTTP_NOT_FOUND, "Not Found", "text/plain", strlen(msgbuf), squid_curtime, -2);
         entry->replaceHttpReply(reply);
         entry->append(msgbuf, strlen(msgbuf));
         entry->complete();
index eed3108fb205108855a7170a852b25f82b987d1b..c4113f7e73e824044707c18adf54e39d089ba4c8 100644 (file)
@@ -455,10 +455,7 @@ MimeIcon::created (StoreEntry *newEntry)
 
     HttpReply *reply = new HttpReply;
 
-    HttpVersion version(1, 0);
-
-    reply->setHeaders(version, HTTP_OK, NULL,
-                      mimeGetContentType(icon), sb.st_size, sb.st_mtime, -1);
+    reply->setHeaders(HTTP_OK, NULL, mimeGetContentType(icon), sb.st_size, sb.st_mtime, -1);
 
     reply->cache_control = httpHdrCcCreate();
 
index 57aecd1c0ed47fd685c5abf0895cb165e53f7ef2..c42ed8a6583f69e5eda9851404095788733fcae0 100644 (file)
@@ -151,7 +151,7 @@ peerAllowedToUse(const peer * p, HttpRequest * request)
 #if PEER_MULTICAST_SIBLINGS
         if (p->type == PEER_MULTICAST && p->options.mcast_siblings &&
                 (request->flags.nocache || request->flags.refresh || request->flags.loopdetect || request->flags.need_validation))
-            debugs(15, 2, "peerAllowedToUse(" << p->name << ", " << request->host << ") : multicast-siblings optimization match");
+            debugs(15, 2, "peerAllowedToUse(" << p->name << ", " << request->GetHost() << ") : multicast-siblings optimization match");
 #endif
         if (request->flags.nocache)
             return 0;
index 4acd9c0ce63dc5561c360a14b2cb4746021cdb2a..69b93059dc3842d488d30b107ca687700e319b58 100644 (file)
@@ -692,10 +692,9 @@ StoreEntry::setPublicKey()
             /* Create "vary" base object */
             String vary;
             StoreEntry *pe = storeCreateEntry(mem_obj->url, mem_obj->log_url, request->flags, request->method);
-            HttpVersion version(1, 0);
             /* We are allowed to do this typecast */
             HttpReply *rep = new HttpReply;
-            rep->setHeaders(version, HTTP_OK, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime + 100000);
+            rep->setHeaders(HTTP_OK, "Internal marker object", "x-squid-internal/vary", -1, -1, squid_curtime + 100000);
             vary = mem_obj->getReply()->header.getList(HDR_VARY);
 
             if (vary.size()) {
index 0173b93643b6eb8338e3207ec8b5df9b8492ebf3..ac0678dfedd674aaf7fa1a01bfc31ab728a3010d 100644 (file)
@@ -420,10 +420,9 @@ storeDigestRewriteResume(void)
     e->setPublicKey();
     /* fake reply */
     HttpReply *rep = new HttpReply;
-    HttpVersion version(1, 0);
-    rep->setHeaders(version, HTTP_OK, "Cache Digest OK",
-                    "application/cache-digest", store_digest->mask_size + sizeof(sd_state.cblock),
-                    squid_curtime, squid_curtime + Config.digest.rewrite_period);
+    rep->setHeaders(HTTP_OK, "Cache Digest OK",
+                    "application/cache-digest", (store_digest->mask_size + sizeof(sd_state.cblock)),
+                    squid_curtime, (squid_curtime + Config.digest.rewrite_period) );
     debugs(71, 3, "storeDigestRewrite: entry expires on " << rep->expires <<
            " (" << std::showpos << (int) (rep->expires - squid_curtime) << ")");
     e->buffer();
index afe844ef1faff943991301441aac48c4943d6618..1e7a59953cec05340af963f3f232b30372623c8a 100644 (file)
@@ -46,7 +46,7 @@ HttpReply::~HttpReply()
 }
 
 void
-HttpReply::setHeaders(HttpVersion ver, http_status status, const char *reason,
+HttpReply::setHeaders(http_status status, const char *reason,
                       const char *ctype, int64_t clen, time_t lmt, time_t expires)
 {
     fatal ("Not implemented");
index 4d3adb8e622bb05675e5e7c8ebee89c8195b0962..a8896adbf605b55d091f5c122f000676090555f3 100644 (file)
@@ -194,9 +194,8 @@ testCoss::testCossSearch()
         request_flags flags;
         flags.cachable = 1;
         StoreEntry *pe = storeCreateEntry("dummy url", "dummy log url", flags, METHOD_GET);
-        HttpVersion version(1, 0);
         HttpReply *rep = (HttpReply *) pe->getReply(); // bypass const
-        rep->setHeaders(version, HTTP_OK, "dummy test object", "x-squid-internal/test", -1, -1, squid_curtime + 100000);
+        rep->setHeaders(HTTP_OK, "dummy test object", "x-squid-internal/test", -1, -1, squid_curtime + 100000);
 
         pe->setPublicKey();
 
index b2b4694c995eaed831adb10b1b35d5a8beee4bb4..856624fc2f8379c7594c1d1c38b3528ab3d4b390 100644 (file)
@@ -161,10 +161,9 @@ testNull::testNullSearch()
         request_flags flags;
         flags.cachable = 1;
         StoreEntry *pe = storeCreateEntry("dummy url", "dummy log url", flags, METHOD_GET);
-        HttpVersion version(1, 0);
         /* We are allowed to do this typecast */
         HttpReply *rep = (HttpReply *) pe->getReply(); // bypass const
-        rep->setHeaders(version, HTTP_OK, "dummy test object", "x-squid-internal/test", -1, -1, squid_curtime + 100000);
+        rep->setHeaders(HTTP_OK, "dummy test object", "x-squid-internal/test", -1, -1, squid_curtime + 100000);
 
         pe->setPublicKey();
 
index 99efc93dc1660118cb2c39302f8b2a28077dee59..e15c0e3d976a746474733580a12d14562ddfed97 100644 (file)
@@ -142,9 +142,8 @@ testUfs::testUfsSearch()
         request_flags flags;
         flags.cachable = 1;
         StoreEntry *pe = storeCreateEntry("dummy url", "dummy log url", flags, METHOD_GET);
-        HttpVersion version(1, 0);
         HttpReply *rep = (HttpReply *) pe->getReply(); // bypass const
-        rep->setHeaders(version, HTTP_OK, "dummy test object", "x-squid-internal/test", -1, -1, squid_curtime + 100000);
+        rep->setHeaders(HTTP_OK, "dummy test object", "x-squid-internal/test", -1, -1, squid_curtime + 100000);
 
         pe->setPublicKey();
 
index e6226cbaa90c30b6705e57e569679345fa5f24b7..e96f2ad1df998e37d5375463833f9c4300f5ed79 100644 (file)
@@ -329,9 +329,6 @@ urnHandleReply(void *data, StoreIOBuffer result)
 
     debugs(52, 3, "urnHandleReply: Called with size=" << (unsigned int)result.length << ".");
 
-    /* Can't be lower because of the goto's */
-    HttpVersion version(1, 0);
-
     if (EBIT_TEST(urlres_e->flags, ENTRY_ABORTED) || result.length == 0 || result.flags.error < 0) {
         urnHandleReplyError(urnState, urlres_e);
         return;
@@ -439,8 +436,7 @@ urnHandleReply(void *data, StoreIOBuffer result)
         "</ADDRESS>\n",
         APP_FULLNAME, getMyHostname());
     rep = new HttpReply;
-    rep->setHeaders(version, HTTP_MOVED_TEMPORARILY, NULL,
-                    "text/html", mb->contentSize(), 0, squid_curtime);
+    rep->setHeaders(HTTP_MOVED_TEMPORARILY, NULL, "text/html", mb->contentSize(), 0, squid_curtime);
 
     if (urnState->flags.force_menu) {
         debugs(51, 3, "urnHandleReply: forcing menu");
index ff7f52c25aad69e08347f644340de40b61a47e89..d7297c485817eb5df341cf99ca239fac8fa1616b 100644 (file)
@@ -128,8 +128,7 @@ WhoisState::setReplyToOK(StoreEntry *sentry)
 {
     HttpReply *reply = new HttpReply;
     sentry->buffer();
-    HttpVersion version(1, 0);
-    reply->setHeaders(version, HTTP_OK, "Gatewaying", "text/plain", -1, -1, -2);
+    reply->setHeaders(HTTP_OK, "Gatewaying", "text/plain", -1, -1, -2);
     sentry->replaceHttpReply(reply);
 }