make sure the path matches exactly in GET, and check that the client actually made a GET request

This commit is contained in:
Alp Mestanogullari 2014-10-21 16:31:22 +02:00
parent 45a625c72c
commit 85f883f4de
1 changed files with 9 additions and 7 deletions

View File

@ -64,13 +64,15 @@ class HasServer layout where
instance ToJSON result => HasServer (Get result) where
type Server (Get result) = (EitherT (Int, String) IO result)
route Proxy action _request = do
e <- runEitherT action
return $ Just $ case e of
Right output ->
responseLBS ok200 [("Content-Type", "application/json")] (encode output)
Left (status, message) ->
responseLBS (mkStatus status (cs message)) [] (cs message)
route Proxy action request
| null (pathInfo request) && requestMethod request == methodGet = do
e <- runEitherT action
return $ Just $ case e of
Right output ->
responseLBS ok200 [("Content-Type", "application/json")] (encode output)
Left (status, message) ->
responseLBS (mkStatus status (cs message)) [] (cs message)
| otherwise = return Nothing
instance (KnownSymbol path, HasServer sublayout) => HasServer (path :> sublayout) where
type Server (path :> sublayout) = path :> (Server sublayout)