From: Francesco Chemolli Date: Wed, 12 Sep 2012 17:52:37 +0000 (+0200) Subject: More RequestFlags getters/setters X-Git-Tag: sourceformat-review-1~6^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=944b056969334d5ca374f04fc2c4684752f18074;p=thirdparty%2Fsquid.git More RequestFlags getters/setters --- diff --git a/src/RequestFlags.h b/src/RequestFlags.h index 6eae0cb658..2d876b64b3 100644 --- a/src/RequestFlags.h +++ b/src/RequestFlags.h @@ -37,8 +37,8 @@ public: RequestFlags(): nocache(0), ims(0), auth(0), cachable(0), hierarchical(0), loopdetect(0), proxy_keepalive(0), proxying(0), - refresh(0), redirected(0), need_validation(0), - fail_on_validation_err(0), stale_if_hit(0), nocache_hack(false), accelerated_(false), + refresh(0), redirected(false), need_validation(false), + fail_on_validation_err(false), stale_if_hit(false), nocache_hack(false), accelerated_(false), ignore_cc(false), intercepted_(false), hostVerified_(false), spoof_client_ip(false), internal(false), internalclient(false), must_keepalive(false), connection_auth_wanted(false), connection_auth_disabled(false), connection_proxy_auth(false), pinned_(false), canRePin_(false), authSent_(false), noDirect_(false), chunkedReply_(false), @@ -57,11 +57,6 @@ public: unsigned int proxy_keepalive :1; unsigned int proxying :1; /* this should be killed, also in httpstateflags */ unsigned int refresh :1; - unsigned int redirected :1; - unsigned int need_validation :1; - unsigned int fail_on_validation_err :1; ///< whether we should fail if validation fails - unsigned int stale_if_hit :1; ///< reply is stale if it is a hit - /* for changing/ignoring no-cache requests. Unused unless USE_HTTP_VIOLATIONS */ // When adding new flags, please update cloneAdaptationImmune() as needed. bool resetTCP() const; @@ -152,7 +147,25 @@ public: * Compilers will have an easy time optimizing to a NOP otherwise. */ void hackNocache() { if (USE_HTTP_VIOLATIONS) nocache_hack=true; } bool noCacheHackEnabled() const { return USE_HTTP_VIOLATIONS && nocache_hack; } + + void setStaleIfHit() { stale_if_hit=true; } + void clearStaleIfHit() { stale_if_hit=false; } + bool staleIfHit() const { return stale_if_hit; } + + void setFailOnValidationError() { fail_on_validation_err=true; } + bool failOnValidationError() const { return fail_on_validation_err; } + + bool validationNeeded() const { return need_validation; } + void setNeedValidation() { need_validation=true; } + + bool isRedirected() const { return redirected; } + void markRedirected() { redirected=true; } private: + bool redirected :1; + bool need_validation :1; + bool fail_on_validation_err :1; ///< whether we should fail if validation fails + bool stale_if_hit :1; ///< reply is stale if it is a hit + /* for changing/ignoring no-cache requests. Unused unless USE_HTTP_VIOLATIONS */ bool nocache_hack :1; bool accelerated_ :1; ///logType = LOG_TCP_REFRESH_UNMODIFIED; - http->request->flags.stale_if_hit = 0; // old_entry is no longer stale + http->request->flags.clearStaleIfHit(); // old_entry is no longer stale // update headers on existing entry old_rep->updateOnNotModified(http->storeEntry()->getReply()); @@ -419,7 +419,7 @@ clientReplyContext::handleIMSReply(StoreIOBuffer result) } // origin replied with an error - else if (http->request->flags.fail_on_validation_err) { + else if (http->request->flags.failOnValidationError()) { http->logType = LOG_TCP_REFRESH_FAIL_ERR; debugs(88, 3, "handleIMSReply: origin replied with error " << status << ", forwarding to client due to fail_on_validation_err"); @@ -557,7 +557,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result) * request. Otherwise two siblings could generate a loop if * both have a stale version of the object. */ - r->flags.need_validation = 1; + r->flags.setNeedValidation(); if (e->lastmod < 0) { /* @@ -1373,9 +1373,9 @@ clientReplyContext::buildReplyHeader() } // add Warnings required by RFC 2616 if serving a stale hit - if (http->request->flags.stale_if_hit && logTypeIsATcpHit(http->logType)) { + if (http->request->flags.staleIfHit() && logTypeIsATcpHit(http->logType)) { hdr->putWarning(110, "Response is stale"); - if (http->request->flags.need_validation) + if (http->request->flags.validationNeeded()) hdr->putWarning(111, "Revalidation failed"); } diff --git a/src/client_side_request.cc b/src/client_side_request.cc index ad43e353fe..a3f0a46c62 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -1231,7 +1231,7 @@ ClientRequestContext::clientRedirectDone(char *result) debugs(61,2, HERE << "URL-rewriter diverts URL from " << urlCanonical(old_request) << " to " << urlCanonical(new_request)); // update the new request to flag the re-writing was done on it - new_request->flags.redirected = 1; + new_request->flags.markRedirected(); // unlink bodypipe from the old request. Not needed there any longer. if (old_request->body_pipe != NULL) { diff --git a/src/forward.cc b/src/forward.cc index 160dd74452..831663d948 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -1251,7 +1251,7 @@ FwdState::reforward() ErrorState * FwdState::makeConnectingError(const err_type type) const { - return new ErrorState(type, request->flags.need_validation ? + return new ErrorState(type, request->flags.validationNeeded() ? HTTP_GATEWAY_TIMEOUT : HTTP_SERVICE_UNAVAILABLE, request); } diff --git a/src/http.cc b/src/http.cc index fa1edf0c68..fcd2f59c02 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1870,7 +1870,7 @@ copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, co */ if (request->peer_domain) hdr_out->putStr(HDR_HOST, request->peer_domain); - else if (request->flags.redirected && !Config.onoff.redir_rewrites_host) + else if (request->flags.isRedirected() && !Config.onoff.redir_rewrites_host) hdr_out->addEntry(e->clone()); else { /* use port# only if not default */ diff --git a/src/neighbors.cc b/src/neighbors.cc index 3677cf4353..5f8014bfdb 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -161,7 +161,7 @@ peerAllowedToUse(const CachePeer * p, HttpRequest * request) if (neighborType(p, request) == PEER_SIBLING) { #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)) + (request->flags.nocache || request->flags.refresh || request->flags.loopdetect || request->flags.validationNeeded())) debugs(15, 2, "peerAllowedToUse(" << p->name << ", " << request->GetHost() << ") : multicast-siblings optimization match"); #endif if (request->flags.nocache) @@ -173,7 +173,7 @@ peerAllowedToUse(const CachePeer * p, HttpRequest * request) if (request->flags.loopdetect) return false; - if (request->flags.need_validation) + if (request->flags.validationNeeded()) return false; } diff --git a/src/peer_select.cc b/src/peer_select.cc index a3730daa77..3c7ab61790 100644 --- a/src/peer_select.cc +++ b/src/peer_select.cc @@ -233,7 +233,7 @@ peerSelectDnsPaths(ps_state *psstate) // To resolve this we must use only the original client destination when going DIRECT // on intercepted traffic which failed Host verification const HttpRequest *req = psstate->request; - const bool isIntercepted = !req->flags.redirected && + const bool isIntercepted = !req->flags.isRedirected() && (req->flags.intercepted() || req->flags.spoofClientIp()); const bool useOriginalDst = Config.onoff.client_dst_passthru || !req->flags.hostVerified(); const bool choseDirect = fs && fs->code == HIER_DIRECT; diff --git a/src/refresh.cc b/src/refresh.cc index 4cac5a0fe6..571e25073d 100644 --- a/src/refresh.cc +++ b/src/refresh.cc @@ -293,7 +293,7 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta) entry->mem_obj->getReply()->cache_control->staleIfError() < staleness) { debugs(22, 3, "refreshCheck: stale-if-error period expired."); - request->flags.fail_on_validation_err = 1; + request->flags.setFailOnValidationError(); } if (EBIT_TEST(entry->flags, ENTRY_REVALIDATE) && staleness > -1 @@ -303,7 +303,7 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta) ) { debugs(22, 3, "refreshCheck: YES: Must revalidate stale response"); if (request) - request->flags.fail_on_validation_err = 1; + request->flags.setFailOnValidationError(); return STALE_MUST_REVALIDATE; } @@ -398,7 +398,7 @@ refreshCheck(const StoreEntry * entry, HttpRequest * request, time_t delta) if ( max_stale >= 0 && staleness > max_stale) { debugs(22, 3, "refreshCheck: YES: max-stale limit"); if (request) - request->flags.fail_on_validation_err = 1; + request->flags.setFailOnValidationError(); return STALE_MAX_STALE; } @@ -494,7 +494,8 @@ refreshCheckHTTP(const StoreEntry * entry, HttpRequest * request) int reason = refreshCheck(entry, request, 0); ++ refreshCounts[rcHTTP].total; ++ refreshCounts[rcHTTP].status[reason]; - request->flags.stale_if_hit = refreshIsStaleIfHit(reason); + if (refreshIsStaleIfHit(reason)) + request->flags.setStaleIfHit(); return (Config.onoff.offline || reason < 200) ? 0 : 1; }