Use Content-Type text/csv for CSV responses
This commit is contained in:
@@ -85,7 +85,7 @@ app conf reqBody req =
|
|||||||
. parseSimpleQuery
|
. parseSimpleQuery
|
||||||
$ rawQueryString req
|
$ rawQueryString req
|
||||||
return $ responseLBS status
|
return $ responseLBS status
|
||||||
[jsonH, contentRange,
|
[if accept == Just "text/csv" then csvH else jsonH, contentRange,
|
||||||
("Content-Location",
|
("Content-Location",
|
||||||
"/" <> cs table <>
|
"/" <> cs table <>
|
||||||
if Prelude.null canonical then "" else "?" <> cs canonical
|
if Prelude.null canonical then "" else "?" <> cs canonical
|
||||||
@@ -248,7 +248,7 @@ rangeStatus from to total
|
|||||||
| otherwise = status200
|
| otherwise = status200
|
||||||
|
|
||||||
bodyForAccept :: Maybe BS.ByteString -> QualifiedTable -> StatementT
|
bodyForAccept :: Maybe BS.ByteString -> QualifiedTable -> StatementT
|
||||||
bodyForAccept accept table =
|
bodyForAccept accept table =
|
||||||
case accept of
|
case accept of
|
||||||
Just "text/csv" -> asCsvWithCount table
|
Just "text/csv" -> asCsvWithCount table
|
||||||
_ -> asJsonWithCount -- defaults to JSON
|
_ -> asJsonWithCount -- defaults to JSON
|
||||||
@@ -276,6 +276,9 @@ requestedSchema v1schema hdrs =
|
|||||||
jsonH :: Header
|
jsonH :: Header
|
||||||
jsonH = (hContentType, "application/json")
|
jsonH = (hContentType, "application/json")
|
||||||
|
|
||||||
|
csvH :: Header
|
||||||
|
csvH = (hContentType, "text/csv")
|
||||||
|
|
||||||
handleJsonObj :: BL.ByteString -> (Object -> H.Tx P.Postgres s Response)
|
handleJsonObj :: BL.ByteString -> (Object -> H.Tx P.Postgres s Response)
|
||||||
-> H.Tx P.Postgres s Response
|
-> H.Tx P.Postgres s Response
|
||||||
handleJsonObj reqBody handler = do
|
handleJsonObj reqBody handler = do
|
||||||
|
|||||||
@@ -126,7 +126,11 @@ spec =
|
|||||||
it "should respond with CSV to 'text/csv' request" $
|
it "should respond with CSV to 'text/csv' request" $
|
||||||
request methodGet "/simple_pk"
|
request methodGet "/simple_pk"
|
||||||
(acceptHdrs "text/csv") ""
|
(acceptHdrs "text/csv") ""
|
||||||
`shouldRespondWith` "k,extra\rxyyx,u\rxYYx,v"
|
`shouldRespondWith` ResponseMatcher {
|
||||||
|
matchBody = Just "k,extra\rxyyx,u\rxYYx,v"
|
||||||
|
, matchStatus = 200
|
||||||
|
, matchHeaders = ["Content-Type" <:> "text/csv"]
|
||||||
|
}
|
||||||
|
|
||||||
describe "Canonical location" $ do
|
describe "Canonical location" $ do
|
||||||
it "Sets Content-Location with alphabetized params" $
|
it "Sets Content-Location with alphabetized params" $
|
||||||
|
|||||||
Reference in New Issue
Block a user