0 | module HTTP.API.Server.Method
2 | import HTTP.API.Server.Interface
6 | parameters {auto loc : HTTPLocal}
7 | checkResponseTypes : All (EncodeVia t) ts -> Request -> Handler ()
8 | checkResponseTypes a r =
9 | let mts := forget $
mapProperty (\x => mediaType @{x}) a
10 | in case any (acceptsMedia r.headers) mts of
13 | let msg := myMediaTypeNotAccepted (commaSepS mts) (commaSepS $
accept r.headers)
14 | in throw $
requestErrDetails msg unsupportedMediaType415
17 | Serve ReqMethod where
20 | OutTypes m = MethodResults m
22 | Constraint (M _ _ _ Nothing0) = ()
23 | Constraint (M _ _ fs $
Just0 t) = All (EncodeVia t) fs
25 | outs (M _ _ _ Nothing0) = []
26 | outs (M _ _ _ $
Just0 t) = [t]
28 | canHandle (M m _ _ _) r = m == r.method
29 | fromRequest m r = pure []
30 | adjResponse (M _ s _ Nothing0) _ req resp = pure (setStatus s resp)
31 | adjResponse (M _ s _ $
Just0 _) [v] req resp = do
32 | checkResponseTypes con req
33 | pure $
encodeBody s v req.headers con resp