From f1feaecf27a1a278847227b9b7b417fd843ee92a Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Tue, 14 Oct 2014 11:49:36 -0700 Subject: [PATCH] Fix Content-Location header when there are no params Fixes #68 --- src/Dbapi.hs | 2 +- test/Feature/QuerySpec.hs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Dbapi.hs b/src/Dbapi.hs index c04fa8be0..20532e054 100644 --- a/src/Dbapi.hs +++ b/src/Dbapi.hs @@ -91,7 +91,7 @@ app conn req respond = rawQueryString req return $ addHeaders [ ("Content-Location", - "/" <> cs table <> "?" <> cs canonical + "/" <> cs table <> if null canonical then "" else "?" <> cs canonical )] r ([table], "POST") -> diff --git a/test/Feature/QuerySpec.hs b/test/Feature/QuerySpec.hs index 1d23da085..37fad40fc 100644 --- a/test/Feature/QuerySpec.hs +++ b/test/Feature/QuerySpec.hs @@ -36,7 +36,7 @@ spec = around appWithFixture $ do , matchHeaders = ["Content-Range" <:> "0-1/2"] } - describe "Canonical location" $ + describe "Canonical location" $ do it "Sets Content-Location with alphabetized params" $ get "/no_pk?b=eq.1&a=eq.1" `shouldRespondWith` ResponseMatcher { @@ -44,3 +44,11 @@ spec = around appWithFixture $ do , matchStatus = 200 , matchHeaders = ["Content-Location" <:> "/no_pk?a=eq.1&b=eq.1"] } + + it "Omits question mark when there are no params" $ + get "/no_pk" + `shouldRespondWith` ResponseMatcher { + matchBody = Just "[]" + , matchStatus = 200 + , matchHeaders = ["Content-Location" <:> "/no_pk"] + }