From: Amos Jeffries Date: Sat, 6 Feb 2010 06:32:11 +0000 (+1300) Subject: Author: Henrik Nordstrom X-Git-Tag: SQUID_3_2_0_1~429 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11992b6fa57fc6c7c058a53d9077c12ae6c9cdde;p=thirdparty%2Fsquid.git Author: Henrik Nordstrom Clean up use of httpReplySetHeaders to be consistent across the code, and remove the unneeded http_version argument. Ported from 2.7 --- diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 50af61ba54..66fe3ed2a4 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -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); diff --git a/src/HttpReply.h b/src/HttpReply.h index 1b0a55a1cd..9bd8c46ec1 100644 --- a/src/HttpReply.h +++ b/src/HttpReply.h @@ -37,8 +37,10 @@ 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 */ diff --git a/src/cache_manager.cc b/src/cache_manager.cc index fec0086866..dc8310857a 100644 --- a/src/cache_manager.cc +++ b/src/cache_manager.cc @@ -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); } diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 8d37cb327d..4e7243ae7d 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -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(); diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 2cb7d92bb6..82c52557bd 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -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); diff --git a/src/errorpage.cc b/src/errorpage.cc index f3e6cb553b..834c6587c8 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -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 diff --git a/src/ftp.cc b/src/ftp.cc index fe97f65403..6d20ba8434 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -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); } diff --git a/src/gopher.cc b/src/gopher.cc index 4003b70543..293059ee46 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -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); diff --git a/src/http.cc b/src/http.cc index 1d7c99daaf..22d9014116 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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() : "/", diff --git a/src/icmp/net_db.cc b/src/icmp/net_db.cc index 66f8d3ff04..32df89cdc1 100644 --- a/src/icmp/net_db.cc +++ b/src/icmp/net_db.cc @@ -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 diff --git a/src/internal.cc b/src/internal.cc index 51d20d80bd..b152feccfb 100644 --- a/src/internal.cc +++ b/src/internal.cc @@ -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(); diff --git a/src/mime.cc b/src/mime.cc index eed3108fb2..c4113f7e73 100644 --- a/src/mime.cc +++ b/src/mime.cc @@ -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(); diff --git a/src/neighbors.cc b/src/neighbors.cc index 57aecd1c0e..c42ed8a658 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -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; diff --git a/src/store.cc b/src/store.cc index 4acd9c0ce6..69b93059dc 100644 --- a/src/store.cc +++ b/src/store.cc @@ -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()) { diff --git a/src/store_digest.cc b/src/store_digest.cc index 0173b93643..ac0678dfed 100644 --- a/src/store_digest.cc +++ b/src/store_digest.cc @@ -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(); diff --git a/src/tests/stub_HttpReply.cc b/src/tests/stub_HttpReply.cc index afe844ef1f..1e7a59953c 100644 --- a/src/tests/stub_HttpReply.cc +++ b/src/tests/stub_HttpReply.cc @@ -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"); diff --git a/src/tests/testCoss.cc b/src/tests/testCoss.cc index 4d3adb8e62..a8896adbf6 100644 --- a/src/tests/testCoss.cc +++ b/src/tests/testCoss.cc @@ -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(); diff --git a/src/tests/testNull.cc b/src/tests/testNull.cc index b2b4694c99..856624fc2f 100644 --- a/src/tests/testNull.cc +++ b/src/tests/testNull.cc @@ -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(); diff --git a/src/tests/testUfs.cc b/src/tests/testUfs.cc index 99efc93dc1..e15c0e3d97 100644 --- a/src/tests/testUfs.cc +++ b/src/tests/testUfs.cc @@ -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(); diff --git a/src/urn.cc b/src/urn.cc index e6226cbaa9..e96f2ad1df 100644 --- a/src/urn.cc +++ b/src/urn.cc @@ -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) "\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"); diff --git a/src/whois.cc b/src/whois.cc index ff7f52c25a..d7297c4858 100644 --- a/src/whois.cc +++ b/src/whois.cc @@ -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); }