Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

proper handling of Location

  • Loading branch information...
commit a1a8370f45bdd3581c5c309096e4da6a4b882b2e 1 parent 937f260
@larrytheliquid authored
Showing with 31 additions and 15 deletions.
  1. +15 −0 doc/notes.txt
  2. +16 −15 src/Lemmachine/Format/Response.agda
View
15 doc/notes.txt
@@ -282,3 +282,18 @@ need a created? hook for POST response
A valid Content-Length is required on all HTTP/1.0 POST requests. An
HTTP/1.0 server should respond with a 400 (bad request) message if it
cannot determine the length of the request message's content.
+
+
+if-modified-since -> cache
+
+ In this case,
+ either 200 (ok) or 204 (no content) is the appropriate response
+ status, depending on whether or not the response includes an entity
+ that describes the result.
+
+ If a resource has been created on the origin server, the response
+ should be 201 (created) and contain an entity (preferably of type
+ "text/html") which describes the status of the request and refers to
+ the new resource.
+
+preferred choice hook for 300 + including Location
View
31 src/Lemmachine/Format/Response.agda
@@ -30,14 +30,11 @@ Method-Response-Format GET = GET-Response-Format
Method-Response-Format HEAD = HEAD-Response-Format
Method-Response-Format POST = POST-Response-Format
--- TODO: Properly comply with 3xx & 201 wrt optional/required
Location-Format : Method Code Format
-Location-Format _ 300-Multiple-Choices = Required-Header Location
+Location-Format _ 300-Multiple-Choices = Optional-Header Location
Location-Format _ 301-Moved-Permanently = Required-Header Location
Location-Format _ 302-Moved-Temporarily = Required-Header Location
-Location-Format _ 304-Not-Modified = Required-Header Location
-Location-Format POST 201-Created = Required-Header Location
-Location-Format _ _ = End
+Location-Format _ _ = Optional-Header Location
WWW-Authenticate-Format : Code Format
WWW-Authenticate-Format 401-Unauthorized = Required-Header WWW-Authenticate
@@ -46,7 +43,7 @@ WWW-Authenticate-Format _ = End
Entity-Body-Format : Format Method Code Format
Entity-Body-Format x _ 204-No-Content = x >>- CRLF >> End
Entity-Body-Format x _ 304-Not-Modified = x >>- CRLF >> End
-Entity-Body-Format x m _ =
+Entity-Body-Format x m c =
Optional-Header Allow >>-
Optional-Header Content-Encoding >>-
Required-Header Content-Length >>= λ c-l
@@ -55,18 +52,22 @@ Entity-Body-Format x m _ =
Optional-Header Last-Modified >>-
x >>-
CRLF >>
- f m (proj₁ c-l) (proj₁ (proj₂ c-l))
+ f m c (proj₁ c-l) (proj₁ (proj₂ c-l))
where
- f : Method (s : Single Content-Length) Header-Value (proj s) Format
- f HEAD _ _ = End
- f _ (single ._) n = Base (STR n)
+ f : Method Code (s : Single Content-Length) Header-Value (proj s) Format
+ f HEAD _ _ _ = End
+ f _ 300-Multiple-Choices (single ._) zero = Fail
+ f _ 301-Moved-Permanently (single ._) zero = Fail
+ f _ 302-Moved-Temporarily (single ._) zero = Fail
+ f _ 304-Not-Modified (single ._) (suc _) = Fail
+ f _ _ (single ._) n = Base (STR n)
Full-Response-Format : Method Format
Full-Response-Format m =
Base VERSION >>-
SP >>
Base CODE >>= λ c
- guard m c >>
+ Require-POST-If-Created m c >>
SP >>
Base REASON-PHRASE >>-
CRLF >>
@@ -76,10 +77,10 @@ Full-Response-Format m =
where
- guard : Method Code Format
- guard GET 201-Created = Fail
- guard HEAD 201-Created = Fail
- guard _ _ = End
+ Require-POST-If-Created : Method Code Format
+ Require-POST-If-Created GET 201-Created = Fail
+ Require-POST-If-Created HEAD 201-Created = Fail
+ Require-POST-If-Created _ _ = End
Response-Format : Maybe Method Format
Response-Format nothing = Simple-Response-Format
Please sign in to comment.
Something went wrong with that request. Please try again.