WIP: converting App

This commit is contained in:
Joe Nelson
2015-11-19 20:45:24 -08:00
parent b6a58935f3
commit c80ab6be0f
3 changed files with 143 additions and 114 deletions
+6 -2
View File
@@ -59,6 +59,8 @@ data Intent = Intent {
, iPreferRepresentation :: Bool
-- | If client wants first row as raw object
, iPreferSingular :: Bool
-- | Whether the client wants a result count (slower)
, iPreferCount :: Bool
}
-- | Examines HTTP request and translates it into user intent.
@@ -94,12 +96,13 @@ userIntent schema req reqBody =
"Content-type not acceptable: " <> accept in
Intent action
(rangeRequested hdrs)
(if singular then Nothing else rangeRequested hdrs)
target
(pickContentType $ lookupHeader "accept")
reqPayload
(hasPrefer "return=representation")
(hasPrefer "plurality=singular")
singular
(not $ hasPrefer "count=none")
where
path = pathInfo req
@@ -107,6 +110,7 @@ userIntent schema req reqBody =
hdrs = requestHeaders req
lookupHeader = flip lookup hdrs
hasPrefer val = any (\(h,v) -> h == "Prefer" && v == val) hdrs
singular = (hasPrefer "plurality=singular")
-- PRIVATE ---------------------------------------------------------------