diff --git a/CHANGELOG.md b/CHANGELOG.md index aa6041318..4b3c61649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased + +### Fixed +- Accepts */* in Accept header - @diogob + ## [0.2.11.0] - 2015-08-28 ### Added - Negate any filter in a uniform way, e.g. `?col=not.eq=foo` - @diogob diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index 4dae952ed..55ce3a735 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -292,19 +292,21 @@ jsonMT = "application/json" csvMT :: BS.ByteString csvMT = "text/csv" +allMT :: BS.ByteString +allMT = "*/*" + jsonH :: Header jsonH = (hContentType, jsonMT) contentTypeForAccept :: Maybe BS.ByteString -> Maybe BS.ByteString contentTypeForAccept accept - | isNothing accept || hasJson = Just jsonMT - | hasCsv = Just csvMT + | isNothing accept || has allMT || has jsonMT = Just jsonMT + | has csvMT = Just csvMT | otherwise = Nothing where Just acceptH = accept findInAccept = flip find $ parseHttpAccept acceptH - hasJson = isJust $ findInAccept $ BS.isPrefixOf jsonMT - hasCsv = isJust $ findInAccept $ BS.isPrefixOf csvMT + has = isJust . findInAccept . BS.isPrefixOf bodyForAccept :: BS.ByteString -> QualifiedIdentifier -> StatementT bodyForAccept contentType table diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index 8de67bcee..22af09411 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -184,6 +184,11 @@ spec = (acceptHdrs "text/unknowntype") "" `shouldRespondWith` 415 + it "should respond correctly to */* in accept header" $ + request methodGet "/simple_pk" + (acceptHdrs "*/*") "" + `shouldRespondWith` 200 + it "should respond correctly to multiple types in accept header" $ request methodGet "/simple_pk" (acceptHdrs "text/unknowntype, text/csv") ""