Merge pull request #275 from diogob/fix_all_media_types_in_accept
Fix */* in accept headers
This commit is contained in:
@@ -3,6 +3,11 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Accepts */* in Accept header - @diogob
|
||||||
|
|
||||||
## [0.2.11.0] - 2015-08-28
|
## [0.2.11.0] - 2015-08-28
|
||||||
### Added
|
### Added
|
||||||
- Negate any filter in a uniform way, e.g. `?col=not.eq=foo` - @diogob
|
- Negate any filter in a uniform way, e.g. `?col=not.eq=foo` - @diogob
|
||||||
|
|||||||
@@ -292,19 +292,21 @@ jsonMT = "application/json"
|
|||||||
csvMT :: BS.ByteString
|
csvMT :: BS.ByteString
|
||||||
csvMT = "text/csv"
|
csvMT = "text/csv"
|
||||||
|
|
||||||
|
allMT :: BS.ByteString
|
||||||
|
allMT = "*/*"
|
||||||
|
|
||||||
jsonH :: Header
|
jsonH :: Header
|
||||||
jsonH = (hContentType, jsonMT)
|
jsonH = (hContentType, jsonMT)
|
||||||
|
|
||||||
contentTypeForAccept :: Maybe BS.ByteString -> Maybe BS.ByteString
|
contentTypeForAccept :: Maybe BS.ByteString -> Maybe BS.ByteString
|
||||||
contentTypeForAccept accept
|
contentTypeForAccept accept
|
||||||
| isNothing accept || hasJson = Just jsonMT
|
| isNothing accept || has allMT || has jsonMT = Just jsonMT
|
||||||
| hasCsv = Just csvMT
|
| has csvMT = Just csvMT
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
where
|
where
|
||||||
Just acceptH = accept
|
Just acceptH = accept
|
||||||
findInAccept = flip find $ parseHttpAccept acceptH
|
findInAccept = flip find $ parseHttpAccept acceptH
|
||||||
hasJson = isJust $ findInAccept $ BS.isPrefixOf jsonMT
|
has = isJust . findInAccept . BS.isPrefixOf
|
||||||
hasCsv = isJust $ findInAccept $ BS.isPrefixOf csvMT
|
|
||||||
|
|
||||||
bodyForAccept :: BS.ByteString -> QualifiedIdentifier -> StatementT
|
bodyForAccept :: BS.ByteString -> QualifiedIdentifier -> StatementT
|
||||||
bodyForAccept contentType table
|
bodyForAccept contentType table
|
||||||
|
|||||||
@@ -184,6 +184,11 @@ spec =
|
|||||||
(acceptHdrs "text/unknowntype") ""
|
(acceptHdrs "text/unknowntype") ""
|
||||||
`shouldRespondWith` 415
|
`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" $
|
it "should respond correctly to multiple types in accept header" $
|
||||||
request methodGet "/simple_pk"
|
request methodGet "/simple_pk"
|
||||||
(acceptHdrs "text/unknowntype, text/csv") ""
|
(acceptHdrs "text/unknowntype, text/csv") ""
|
||||||
|
|||||||
Reference in New Issue
Block a user