]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
More RequestFlags getters/setters
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 12 Sep 2012 17:52:37 +0000 (19:52 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 12 Sep 2012 17:52:37 +0000 (19:52 +0200)
src/RequestFlags.h
src/client_side_reply.cc
src/client_side_request.cc
src/forward.cc
src/http.cc
src/neighbors.cc
src/peer_select.cc
src/refresh.cc

index 6eae0cb658cf528fd99d2edf3fc57fd65eb45501..2d876b64b34c1866db065202262d8b4154da407a 100644 (file)
@@ -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; ///<request is accelerated
     bool ignore_cc :1; ///< ignore Cache-Control
index b4e178d4936d6ede8e1595877a09428a80fb25fd..e5b2bd8466052bb73e7c9524c11cd201d93be7c3 100644 (file)
@@ -390,7 +390,7 @@ clientReplyContext::handleIMSReply(StoreIOBuffer result)
     // origin replied 304
     if (status == HTTP_NOT_MODIFIED) {
         http->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");
     }
 
index ad43e353fec93a0c1761820a8d9b78b6c299ef05..a3f0a46c62ca2eb677f64857806e8cbe54fecfe7 100644 (file)
@@ -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) {
index 160dd74452674b2f501814eb3030f34bc1108ad6..831663d948636ce7ed4d8556d551833aefb74131 100644 (file)
@@ -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);
 }
 
index fa1edf0c68cb4795f7240273a85c6c08f6c861c2..fcd2f59c02d1f90a0bef66e3cce5e6ba90146924 100644 (file)
@@ -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 */
index 3677cf435380f88303d9f47f1e64a982148a0ea8..5f8014bfdb88a495fd66a17f626125598faa272d 100644 (file)
@@ -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;
     }
 
index a3730daa7747360a4b02765ecc96393fb375d250..3c7ab61790a6110a3a44834300bda5c332438151 100644 (file)
@@ -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;
index 4cac5a0fe6c87ac8726f8c07837fa3eb2ccc594a..571e25073d5808fa83ede264340b48535dafc62e 100644 (file)
@@ -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;
 }