Cookies support clj-time intervals and dates #55

weavejester opened this Issue Mar 3, 2012 · 4 comments

2 participants


In ring.middleware.wrap-cookies:

  • The :max-age key should support JodaTime Intervals (via clj-time)
  • The :expires key should support JodaTime DateTimes and Java Dates

Existing Ring 1.0 behaviour should not be affected (i.e. :max-age should handle an integer, etc.)



The only thing left before my work so far (see commits referenced above) can be merged in is for checks to test whether :max-age and :expires only accept Interval and DateTime objects, respectively.

How should I notify the user that they're providing incorrect data as input? What's the preferred way?


A precondition would probably be the best solution.


How should that be laid out? I was thinking about something like this:

:pre (if (and (= key :max-size) (= value (str value))
         (instance? Interval value))

But are there better ways of laying this out?


The valid-attr? function is already used to validate the attribute via a pre-condition. You can extend the function with a conditional and more tests.

@weavejester weavejester pushed a commit that closed this issue Mar 21, 2012
@KushalP KushalP Add clj-time Intervals/DateTime for :max-age and :expires (fixes #55)
- Add a test for :max-age and :expires to (wrap-cookies ...). There were
  no real tests to exercise the base input cases (int, string) which the
  comment block states. This test just makes sure it fulfils that
- clj-time is now a project dependency
- :max-age accepts an Interval as input. Updated (write-attr-map ...) to
  accept an Interval (from JodaTime) as well as an int. The interface
  from clj-time is used.
- :expires accepts a DateTime object. It converts the DateTime object in
  the equivalent RFC822 which the cookie spec requires.
- Added pre-conditions for :max-age and :expires to make sure that they
  only accept Interval and DateTime, respectively.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment