@@ -41,7 +41,6 @@ import PostgREST.ApiRequest (Action (..),
41
41
ApiRequest (.. ),
42
42
InvokeMethod (.. ),
43
43
Mutation (.. ),
44
- PathInfo (.. ),
45
44
Payload (.. ))
46
45
import PostgREST.Config (AppConfig (.. ))
47
46
import PostgREST.Error (Error (.. ))
@@ -123,15 +122,15 @@ data InspectPlan = InspectPlan {
123
122
wrappedReadPlan :: QualifiedIdentifier -> AppConfig -> SchemaCache -> ApiRequest -> Either Error WrappedReadPlan
124
123
wrappedReadPlan identifier conf sCache apiRequest@ ApiRequest {iPreferences= Preferences {.. },.. } = do
125
124
rPlan <- readPlan identifier conf sCache apiRequest
126
- mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iPathInfo iAcceptMediaType
125
+ mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iAcceptMediaType
127
126
if not (null invalidPrefs) && preferHandling == Just Strict then Left $ ApiRequestError $ InvalidPreferences invalidPrefs else Right ()
128
127
return $ WrappedReadPlan rPlan SQL. Read (mediaToAggregate mediaType apiRequest) mediaType
129
128
130
129
mutateReadPlan :: Mutation -> ApiRequest -> QualifiedIdentifier -> AppConfig -> SchemaCache -> Either Error MutateReadPlan
131
130
mutateReadPlan mutation apiRequest@ ApiRequest {iPreferences= Preferences {.. },.. } identifier conf sCache = do
132
131
rPlan <- readPlan identifier conf sCache apiRequest
133
132
mPlan <- mutatePlan mutation identifier apiRequest sCache rPlan
134
- mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iPathInfo iAcceptMediaType
133
+ mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iAcceptMediaType
135
134
if not (null invalidPrefs) && preferHandling == Just Strict then Left $ ApiRequestError $ InvalidPreferences invalidPrefs else Right ()
136
135
return $ MutateReadPlan rPlan mPlan SQL. Write (mediaToAggregate mediaType apiRequest) mediaType
137
136
@@ -157,15 +156,15 @@ callReadPlan identifier conf sCache apiRequest@ApiRequest{iPreferences=Preferenc
157
156
(InvPost , Routine. Immutable ) -> SQL. Read
158
157
(InvPost , Routine. Volatile ) -> SQL. Write
159
158
cPlan = callPlan proc apiRequest paramKeys args rPlan
160
- mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iPathInfo iAcceptMediaType
159
+ mediaType <- mapLeft ApiRequestError $ negotiateContent conf iAction iAcceptMediaType
161
160
if not (null invalidPrefs) && preferHandling == Just Strict then Left $ ApiRequestError $ InvalidPreferences invalidPrefs else Right ()
162
161
return $ CallReadPlan rPlan cPlan txMode proc (mediaToAggregate mediaType apiRequest) mediaType
163
162
where
164
163
qsParams' = QueryParams. qsParams iQueryParams
165
164
166
165
inspectPlan :: AppConfig -> ApiRequest -> Either Error InspectPlan
167
166
inspectPlan conf apiRequest = do
168
- mediaType <- mapLeft ApiRequestError $ negotiateContent conf (iAction apiRequest) (iPathInfo apiRequest) ( iAcceptMediaType apiRequest)
167
+ mediaType <- mapLeft ApiRequestError $ negotiateContent conf (iAction apiRequest) (iAcceptMediaType apiRequest)
169
168
return $ InspectPlan mediaType SQL. Read
170
169
171
170
{-|
@@ -851,29 +850,26 @@ mediaToAggregate mt apiReq@ApiRequest{iAction=act, iPreferences=Preferences{pref
851
850
_ -> False
852
851
853
852
-- | Do content negotiation. i.e. choose a media type based on the intersection of accepted/produced media types.
854
- negotiateContent :: AppConfig -> Action -> PathInfo -> [MediaType ] -> Either ApiRequestError MediaType
855
- negotiateContent conf action path accepts =
853
+ negotiateContent :: AppConfig -> Action -> [MediaType ] -> Either ApiRequestError MediaType
854
+ negotiateContent conf action accepts =
856
855
case firstAcceptedPick of
857
856
Just MTAny -> Right MTApplicationJSON -- by default(for */*) we respond with json
858
857
Just mt -> Right mt
859
858
Nothing -> Left . MediaTypeError $ map MediaType. toMime accepts
860
859
where
861
860
-- if there are multiple accepted media types, pick the first
862
- firstAcceptedPick = listToMaybe $ L. intersect accepts $ producedMediaTypes conf action path
861
+ firstAcceptedPick = listToMaybe $ L. intersect accepts $ producedMediaTypes conf action
863
862
864
- producedMediaTypes :: AppConfig -> Action -> PathInfo -> [MediaType ]
865
- producedMediaTypes conf action path =
863
+ producedMediaTypes :: AppConfig -> Action -> [MediaType ]
864
+ producedMediaTypes conf action =
866
865
case action of
867
866
ActionRead _ -> defaultMediaTypes
868
- ActionInvoke _ -> invokeMediaTypes
867
+ ActionInvoke _ -> defaultMediaTypes
869
868
ActionInfo -> defaultMediaTypes
870
869
ActionMutate _ -> defaultMediaTypes
871
870
ActionInspect _ -> inspectMediaTypes
872
871
where
873
872
inspectMediaTypes = [MTOpenAPI , MTApplicationJSON , MTArrayJSONStrip , MTAny ]
874
- invokeMediaTypes =
875
- defaultMediaTypes
876
- ++ [MTOpenAPI | pathIsRootSpec path]
877
873
defaultMediaTypes =
878
874
[MTApplicationJSON , MTArrayJSONStrip , MTSingularJSON True , MTSingularJSON False , MTGeoJSON , MTTextCSV ] ++
879
875
[MTPlan MTApplicationJSON PlanText mempty | configDbPlanEnabled conf] ++ [MTAny ]
0 commit comments