diff --git a/servant-client/test/Servant/ClientTestUtils.hs b/servant-client/test/Servant/ClientTestUtils.hs index e8f8424a..666c847d 100644 --- a/servant-client/test/Servant/ClientTestUtils.hs +++ b/servant-client/test/Servant/ClientTestUtils.hs @@ -133,6 +133,7 @@ type Api = :<|> "captureAll" :> CaptureAll "names" String :> Get '[JSON] [Person] :<|> "body" :> ReqBody '[FormUrlEncoded,JSON] Person :> Post '[JSON] Person :<|> "param" :> QueryParam "name" String :> Get '[FormUrlEncoded,JSON] Person + :<|> "param-echo" :> QueryParam "payload" String :> Get '[JSON] (Maybe String) -- This endpoint makes use of a 'Raw' server because it is not currently -- possible to handle arbitrary binary query param values with -- @servant-server@ @@ -172,6 +173,7 @@ getCapture :: String -> ClientM Person getCaptureAll :: [String] -> ClientM [Person] getBody :: Person -> ClientM Person getQueryParam :: Maybe String -> ClientM Person +getQueryParamEcho :: Maybe String -> ClientM (Maybe String) getQueryParamBinary :: Maybe UrlEncodedByteString -> HTTP.Method -> ClientM Response getQueryParams :: [String] -> ClientM [Person] getQueryFlag :: Bool -> ClientM Bool @@ -199,6 +201,7 @@ getRoot :<|> getCaptureAll :<|> getBody :<|> getQueryParam + :<|> getQueryParamEcho :<|> getQueryParamBinary :<|> getQueryParams :<|> getQueryFlag @@ -229,6 +232,7 @@ server = serve api ( Just "alice" -> return alice Just n -> throwError $ ServerError 400 (n ++ " not found") "" [] Nothing -> throwError $ ServerError 400 "missing parameter" "" []) + :<|> return :<|> const (Tagged $ \request respond -> respond . maybe (Wai.responseLBS HTTP.notFound404 [] "Missing: payload") (Wai.responseLBS HTTP.ok200 [] . LazyByteString.fromStrict) diff --git a/servant-client/test/Servant/SuccessSpec.hs b/servant-client/test/Servant/SuccessSpec.hs index 4b5e00df..ed31f520 100644 --- a/servant-client/test/Servant/SuccessSpec.hs +++ b/servant-client/test/Servant/SuccessSpec.hs @@ -99,6 +99,10 @@ successSpec = beforeAll (startWaiApp server) $ afterAll endWaiApp $ do Left (FailureResponse _ r) <- runClient (getQueryParam (Just "bob")) baseUrl responseStatusCode r `shouldBe` HTTP.Status 400 "bob not found" + it "Servant.API.QueryParam echo special chars" $ \(_, baseUrl) -> do + let payload = Just ":@&=+$," + left show <$> runClient (getQueryParamEcho payload) baseUrl `shouldReturn` Right payload + it "Servant.API.QueryParam binary data" $ \(_, baseUrl) -> do let payload = BS.pack [0, 1, 2, 4, 8, 16, 32, 64, 128] apiCall = getQueryParamBinary (Just $ UrlEncodedByteString payload) HTTP.methodGet