Cookies support clj-time intervals and dates #55

Closed
weavejester opened this Issue Mar 3, 2012 · 4 comments

2 participants

@weavejester
Collaborator

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.)

(See: https://github.com/seancorfield/clj-time)

@KushalP

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?

@weavejester
Collaborator

A precondition would probably be the best solution.

@KushalP

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

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

But are there better ways of laying this out?

@weavejester
Collaborator

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
  contract.
- 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.
75c90aa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment