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

View file

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