Created
March 19, 2011 23:25
-
-
Save klaeufer/877902 to your computer and use it in GitHub Desktop.
Simple Unfiltered example for providing OPTIONS, HEAD, and conditional GET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RootPlan extends Plan { | |
val logger = Logger(classOf[RootPlan]) | |
val creationDate = new java.util.Date | |
val eTag = hashCode.toString | |
val Head = Ok ~> Vary("Accept-Charset", "Accept-Encoding", "Accept-Language", "Accept") | |
val Caching = | |
CacheControl("max-age=3600") ~> | |
LastModified(DateUtils.formatDate(creationDate)) ~> | |
ETag(eTag) | |
def intent = { | |
case OPTIONS(_) => Ok ~> Allow("GET", "HEAD", "OPTIONS") | |
case HEAD(Path(Seg(Nil))) => { | |
logger.debug("HEAD /") | |
Head | |
} | |
case req @ GET(Path(Seg(Nil))) => { | |
logger.debug("GET /") | |
val cached = | |
req match { | |
case IfNoneMatch(xs) => xs contains eTag | |
case IfModifiedSince(xs) => { | |
val sinceDate = DateUtils.parseDate(xs mkString ", ") | |
! creationDate.after(sinceDate) | |
} | |
case _ => false | |
} | |
if (cached) | |
Head ~> Caching ~> NotModified | |
else | |
Head ~> Caching ~> ResponseString( | |
"To register: " + | |
"curl -X PUT -d 'user[password]=pass' -d 'user[email]=you@host' -d 'user[full_name]=Your%20Name' -v http://localhost:8080/users/you") | |
} | |
} | |
} |
Thanks, nice!
…On Fri, Mar 25, 2011 at 18:50, n8han < ***@***.***>wrote:
It's an empty Request object in Dispatch:
http://sourced.implicit.ly/net.databinder/dispatch-http/0.7.8/dispatch/Http.scala.html#9112
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/877902
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's an empty Request object in Dispatch:
http://sourced.implicit.ly/net.databinder/dispatch-http/0.7.8/dispatch/Http.scala.html#9112