Class GuardAction

java.lang.Object
org.frontcache.guard.GuardAction

public class GuardAction extends Object
What a matching guard rule does with the request: reject it, redirect it, explicitly let it through (an exemption placed above a broader rule), or challenge it - send the visitor to a challenge provider's page under /fc-x/<plugin>/, which is a redirect that knows which provider it needs (see challenge(String, GuardAction)).
  • Field Details

  • Method Details

    • reject

      public static GuardAction reject(int status, String body)
    • redirect

      public static GuardAction redirect(int status, String target)
    • challenge

      public static GuardAction challenge(String provider, GuardAction otherwise)
      challenge <provider> [else <reject|redirect>]: a 302 to the page of the plugin offering the provider - when one is started and the node can sign a pass. When either is missing, the else action if there is one, and otherwise the rule acts as a dry run: a node without the plugin serves every request as it would without the rule, and says so. See GuardRuleEngine for the rest of what it knows that a redirect does not (never a non-GET, never an include, never the provider's own path, never a visitor holding a pass).
      Parameters:
      otherwise - a reject or redirect action, or null
    • allow

      public static GuardAction allow()
    • getType

      public GuardAction.Type getType()
    • getStatus

      public int getStatus()
    • getBody

      public String getBody()
    • getTarget

      public String getTarget()
      Returns:
      redirect target as configured, placeholders NOT expanded
    • getProvider

      public String getProvider()
      Returns:
      the challenge provider, or null for any other action
    • getOtherwise

      public GuardAction getOtherwise()
      Returns:
      a challenge's else action, or null
    • getDisposition

      public String getDisposition()
      Returns:
      the disposition string for the log line, or null for ALLOW (not logged)
    • resolveTarget

      public String resolveTarget(RequestContext context)
      Expands ${uri} / ${query} / ${url} / ${url:enc} / ${host} in the redirect target.
      Parameters:
      context - current request
      Returns:
      target ready for the Location header
    • requestURL

      public static String requestURL(RequestContext context)
      Full request URL, as the client would have to type it to get back here. Built here rather than taken from RequestContext.getCurrentRequestURL(), which FrontCacheEngine only populates later and only for cacheable requests - guards run before that. Note the two independent substitutions relative to what the socket saw: the host (see publicHost(RequestContext)) and the scheme. Behind a TLS-terminating proxy the connection reaching this process is plaintext, so the scheme comes from RequestContext.getPublicProtocol() (X-Forwarded-Proto from a trusted peer, or front-cache.public-scheme) and only then from the connection. On the example-site edges roughly one request in ten arrived over the plaintext leg, and each one produced an http:// return URL for an https-only site.
    • toString

      public String toString()
      Overrides:
      toString in class Object