Skip to content

Commit feb5b7d

Browse files
authored
fix: regression that replaces an unknown media type with */* (PostgREST#4013)
1 parent a1009d1 commit feb5b7d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/PostgREST/MediaType.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ decodeMediaType mt = decodeMediaType' $ decodeLatin1 mt
155155
mediaTypeOrError = P.parse tokenizeMediaType "parsec: tokenizeMediaType failed" $ T.unpack mt'
156156
(mainType, subType, params') = case mediaTypeOrError of
157157
Right mt'' -> mt''
158-
Left _ -> ("*", "*", []) -- TODO: Throw mediatype error, would need refactoring because currently Error module depend on MediaType module
158+
Left _ -> (mt',"",[])
159159
params = fromList $ map (first T.toLower) params' -- normalize parameter names to lowercase, per RFC 7321
160160
getPlan fmt = MTVndPlan mtFor fmt $
161161
[PlanAnalyze | inOpts "analyze" ] ++

test/spec/Feature/Query/CustomMediaSpec.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,10 @@ spec = describe "custom media types" $ do
375375
{ matchStatus = 200
376376
, matchHeaders = ["Content-Type" <:> "application/octet-stream"]
377377
}
378+
379+
context "media type parser fails" $ do
380+
it "sends media type as is" $
381+
request methodGet "/items" (acceptHdrs "undefined") ""
382+
`shouldRespondWith`
383+
[json| {"code":"PGRST107","details":null,"hint":null,"message":"None of these media types are available: undefined"} |]
384+
{ matchStatus = 406 }

0 commit comments

Comments
 (0)