From ba86b479f816f125b4652bdf834d3f085c10e851 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Wed, 30 Dec 2020 23:36:31 +0100 Subject: [PATCH] cov: refactor ApiRequest profile header detection --- src/PostgREST/ApiRequest.hs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/PostgREST/ApiRequest.hs b/src/PostgREST/ApiRequest.hs index 745b67f8f..2b969e09d 100644 --- a/src/PostgREST/ApiRequest.hs +++ b/src/PostgREST/ApiRequest.hs @@ -261,12 +261,17 @@ userApiRequest confSchemas rootSpec dbStructure req reqBody profile | length confSchemas <= 1 -- only enable content negotiation by profile when there are multiple schemas specified in the config = Nothing - | action `elem` [ActionCreate, ActionUpdate, ActionSingleUpsert, ActionDelete, ActionInvoke InvPost] -- POST/PATCH/PUT/DELETE don't use the same header as per the spec - = Just $ maybe defaultSchema toS $ lookupHeader "Content-Profile" - | action `elem` [ActionRead True, ActionRead False, ActionInvoke InvGet, ActionInvoke InvHead, - ActionInspect False, ActionInspect True, ActionInfo] - = Just $ maybe defaultSchema toS $ lookupHeader "Accept-Profile" - | otherwise = Nothing + | otherwise = case action of + -- POST/PATCH/PUT/DELETE don't use the same header as per the spec + ActionCreate -> contentProfile + ActionUpdate -> contentProfile + ActionSingleUpsert -> contentProfile + ActionDelete -> contentProfile + ActionInvoke InvPost -> contentProfile + _ -> acceptProfile + where + contentProfile = Just $ maybe defaultSchema toS $ lookupHeader "Content-Profile" + acceptProfile = Just $ maybe defaultSchema toS $ lookupHeader "Accept-Profile" schema = fromMaybe defaultSchema profile target = let