git.iko.soy/typeable/servant
on master help sign in
-Wall police
commitd461726b9a02fa8a1c15b60a1449b1cb18b8fe92 authorAlp Mestanogullari <alpmestan@gmail.com> dateSat 22 Nov 2014, 14:35 (12 years ago) parentdacea01
5 files changed+30−30
src/Servant/API/QueryParam.hs+1−1 src/Servant/API/Raw.hs+2−2 src/Servant/Common/BaseUrl.hs+6−6 src/Servant/Common/Req.hs+19−19 src/Servant/Utils/StaticFiles.hs+2−2
src/Servant/API/QueryParam.hs+1−1
@@ -106,7 +106,7 @@ instance (KnownSymbol sym, ToText a, HasClient sublayout)
106106
107107 clientWithRoute Proxy req paramlist =
108108 clientWithRoute (Proxy :: Proxy sublayout) $
109− foldl' (\ value req -> appendToQueryString pname req value) req paramlist'
109+ foldl' (\ value req' -> appendToQueryString pname req' value) req paramlist'
110110
111111 where pname = cs pname'
112112 pname' = symbolVal (Proxy :: Proxy sym)
src/Servant/API/Raw.hs+2−2
@@ -29,8 +29,8 @@ instance HasClient Raw where
2929 type Client Raw = Method -> BaseUrl -> EitherT String IO (Int, ByteString)
3030
3131 clientWithRoute :: Proxy Raw -> Req -> Client Raw
32− clientWithRoute Proxy req method host =
33− performRequest method req (const True) host
32+ clientWithRoute Proxy req httpMethod host =
33+ performRequest httpMethod req (const True) host
3434
3535
3636instance HasDocs Raw where
src/Servant/Common/BaseUrl.hs+6−6
@@ -19,13 +19,13 @@ data BaseUrl = BaseUrl {
1919 deriving (Show, Eq, Ord, Generic)
2020
2121showBaseUrl :: BaseUrl -> String
22−showBaseUrl (BaseUrl scheme host port) =
22+showBaseUrl (BaseUrl urlscheme host port) =
2323 schemeString ++ "//" ++ host ++ portString
2424 where
25− schemeString = case scheme of
25+ schemeString = case urlscheme of
2626 Http -> "http:"
2727 Https -> "https:"
28− portString = case (scheme, port) of
28+ portString = case (urlscheme, port) of
2929 (Http, 80) -> ""
3030 (Https, 443) -> ""
3131 _ -> ":" ++ show port
@@ -46,6 +46,6 @@ parseBaseUrl s = case parseURI (removeTrailingSlash s) of
4646 then Left ("invalid base url: " ++ s)
4747 else parseBaseUrl ("http://" ++ s)
4848 where
49− removeTrailingSlash s = case lastMay s of
50− Just '/' -> init s
51− _ -> s
49+ removeTrailingSlash str = case lastMay str of
50+ Just '/' -> init str
51+ _ -> str
src/Servant/Common/Req.hs+19−19
@@ -49,15 +49,15 @@ setRQBody :: ByteString -> Req -> Req
4949setRQBody b req = req { reqBody = b }
5050
5151reqToRequest :: (Functor m, MonadThrow m) => Req -> BaseUrl -> m Request
52−reqToRequest req (BaseUrl scheme host port) = fmap (setrqb . setQS ) $ parseUrl url
52+reqToRequest req (BaseUrl reqScheme reqHost reqPort) = fmap (setrqb . setQS ) $ parseUrl url
5353
54− where url = show $ nullURI { uriScheme = case scheme of
54+ where url = show $ nullURI { uriScheme = case reqScheme of
5555 Http -> "http:"
5656 Https -> "https:"
5757 , uriAuthority = Just $
5858 URIAuth { uriUserInfo = ""
59− , uriRegName = host
60− , uriPort = ":" ++ show port
59+ , uriRegName = reqHost
60+ , uriPort = ":" ++ show reqPort
6161 }
6262 , uriPath = reqPath req
6363 }
@@ -79,14 +79,14 @@ __withGlobalManager action = modifyMVar __manager $ \ manager -> do
7979
8080
8181displayHttpRequest :: Method -> String
82−displayHttpRequest method = "HTTP " ++ cs method ++ " request"
82+displayHttpRequest httpmethod = "HTTP " ++ cs httpmethod ++ " request"
8383
8484
8585performRequest :: Method -> Req -> (Int -> Bool) -> BaseUrl -> EitherT String IO (Int, ByteString)
86−performRequest method req isWantedStatus host = do
87− partialRequest <- liftIO $ reqToRequest req host
86+performRequest reqMethod req isWantedStatus reqHost = do
87+ partialRequest <- liftIO $ reqToRequest req reqHost
8888
89− let request = partialRequest { Client.method = method
89+ let request = partialRequest { Client.method = reqMethod
9090 , checkStatus = \ _status _headers _cookies -> Nothing
9191 }
9292
@@ -95,12 +95,12 @@ performRequest method req isWantedStatus host = do
9595 Client.httpLbs request manager
9696 case eResponse of
9797 Left status ->
98− left (displayHttpRequest method ++ " failed with status: " ++ showStatus status)
98+ left (displayHttpRequest reqMethod ++ " failed with status: " ++ showStatus status)
9999
100100 Right response -> do
101101 let status = Client.responseStatus response
102102 unless (isWantedStatus (statusCode status)) $
103− left (displayHttpRequest method ++ " failed with status: " ++ showStatus status)
103+ left (displayHttpRequest reqMethod ++ " failed with status: " ++ showStatus status)
104104 return $ (statusCode status, Client.responseBody response)
105105 where
106106 showStatus (Status code message) =
@@ -109,20 +109,20 @@ performRequest method req isWantedStatus host = do
109109
110110performRequestJSON :: FromJSON result =>
111111 Method -> Req -> Int -> BaseUrl -> EitherT String IO result
112−performRequestJSON method req wantedStatus host = do
113− (_status, responseBody) <- performRequest method req (== wantedStatus) host
112+performRequestJSON reqMethod req wantedStatus reqHost = do
113+ (_status, respBody) <- performRequest reqMethod req (== wantedStatus) reqHost
114114 either
115− (\ message -> left (displayHttpRequest method ++ " returned invalid json: " ++ message))
115+ (\ message -> left (displayHttpRequest reqMethod ++ " returned invalid json: " ++ message))
116116 return
117− (decodeLenient responseBody)
117+ (decodeLenient respBody)
118118
119119
120120catchStatusCodeException :: IO a -> IO (Either Status a)
121−catchStatusCodeException action = catch (Right <$> action) $
122− \ e -> case e of
123− Client.StatusCodeException status _ _ ->
124− return $ Left status
125− e -> throwIO e
121+catchStatusCodeException action =
122+ catch (Right <$> action) $ \e ->
123+ case e of
124+ Client.StatusCodeException status _ _ -> return $ Left status
125+ exc -> throwIO exc
126126
127127-- | Like 'Data.Aeson.decode' but allows all JSON values instead of just
128128-- objects and arrays.
src/Servant/Utils/StaticFiles.hs+2−2
@@ -23,11 +23,11 @@ serveDocumentation proxy _request respond =
2323 respond $ responseLBS ok200 [] $ cs $ toHtml $ markdown $ docs proxy
2424
2525toHtml :: String -> String
26−toHtml markdown =
26+toHtml md =
2727 "<html>" ++
2828 "<body>" ++
2929 "<pre>" ++
30− markdown ++
30+ md ++
3131 "</pre>" ++
3232 "</body>" ++
3333 "</html>"