Class ExpiryCheckHandler


  • public final class ExpiryCheckHandler
    extends Object
    The ExpiryCheckHandler allows you to check the expiry of a request. It also offers methods for setting default values for expiration and timestamps to the request header.
    Author:
    https://github.com/ljucam [Mario Ljuca]
    • Method Detail

      • updateServerTimestampHeader

        public static void updateServerTimestampHeader​(HttpRequest request)
        Checks if a "X-Server-Timestamp" header is set or not. If no valid value is found, the current timestamp is set.
        Parameters:
        request - request
      • updateServerTimestampHeader

        public static void updateServerTimestampHeader​(io.vertx.core.MultiMap headers)
        Checks if a "X-Server-Timestamp" header is set or not. If no valid value is found, the current timestamp is set.
        Parameters:
        headers - headers
      • getExpireAfter

        public static Integer getExpireAfter​(io.vertx.core.MultiMap headers)
        Extracts the value of the "X-Expire-After" header. If the value can't be extracted (not found, invalid, and so on), null is returned.
        Parameters:
        headers - headers
        Returns:
        expire-after time in seconds or null if nothing is found
      • getExpireAfterConcerningCaseOfCorruptHeaderAndInfinite

        public static Optional<Integer> getExpireAfterConcerningCaseOfCorruptHeaderAndInfinite​(io.vertx.core.MultiMap headers)
        Delegates to getExpireValue(String) This is extended version of getExpireAfter(MultiMap) but also returning -1 for infinite.
        Parameters:
        headers - Headers to fetch value from.
        Returns:

        The parsed expire-after value.

        Returns empty in case getExpireValue(String) returned null.

      • getQueueExpireAfter

        public static Integer getQueueExpireAfter​(io.vertx.core.MultiMap headers)
        Extracts the value of the "x-queue-expire-after" header. If the value can't be extracted (not found, invalid, and so on), null is returned.
        Parameters:
        headers - headers
        Returns:
        queue-expire-after time in seconds or null if nothing is found
      • isExpired

        public static boolean isExpired​(io.vertx.core.MultiMap headers,
                                        Long timestamp)
        Checks the expiration based on the given headers and a timstamp in milliseconds.
        Parameters:
        headers - headers
        Returns:
        true if the request has expired, false otherwise
      • getExpirationTime

        public static org.joda.time.DateTime getExpirationTime​(int expireAfter)
        Returns the expiration time, based on the current time (now) in addition with the expireAfter value.
        Parameters:
        expireAfter - - in seconds
        Returns:
        expiration time
      • getExpirationTimeAsString

        public static Optional<String> getExpirationTimeAsString​(int expireAfter)
        Returns:
        Expiration time based on passed expireAfter or empty in case of an infinite expiration.
      • parseDateTime

        public static org.joda.time.DateTime parseDateTime​(String datetime)
        Parses the given string to a DateTime object.
        Parameters:
        datetime - datetime as string
        Returns:
        DateTime
      • printDateTime

        public static String printDateTime​(org.joda.time.DateTime datetime)
        Prints the given datetime as a string.
        Parameters:
        datetime - datetime
        Returns:
        String
      • setExpireAfter

        public static void setExpireAfter​(io.vertx.core.http.HttpServerRequest request,
                                          int expireAfter)
        Sets an "X-Expire-After" header. If such a header already exist, it's overridden by the new value.
        Parameters:
        request - request
        expireAfter - expireAfter
      • setQueueExpireAfter

        public static void setQueueExpireAfter​(io.vertx.core.MultiMap headers,
                                               int queueExpireAfter)
        Sets an "x-queue-expire-after" header. If such a header already exist, it's overridden by the new value.
        Parameters:
        headers - headers
        queueExpireAfter - queueExpireAfter