@@ -15,7 +15,7 @@ import Control.Monad.Catch (Exception, MonadThrow, throwM)
1515import Data.List
1616import Data.Typeable
1717import GHC.Generics
18−import Network.URI
18+import Network.URI hiding (path)
1919import Safe
2020import Text.Read
2121
@@ -31,11 +31,12 @@ data BaseUrl = BaseUrl
3131 { baseUrlScheme :: Scheme -- ^ URI scheme to use
3232 , baseUrlHost :: String -- ^ host (eg "haskell.org")
3333 , baseUrlPort :: Int -- ^ port (eg 80)
34+ , baseUrlPath :: String -- ^ path (eg "/a/b/c")
3435 } deriving (Show, Eq, Ord, Generic)
3536
3637showBaseUrl :: BaseUrl -> String
37−showBaseUrl (BaseUrl urlscheme host port) =
38− schemeString ++ "//" ++ host ++ portString
38+showBaseUrl (BaseUrl urlscheme host port path) =
39+ schemeString ++ "//" ++ host ++ portString ++ path
3940 where
4041 schemeString = case urlscheme of
4142 Http -> "http:"
@@ -52,14 +53,14 @@ parseBaseUrl :: MonadThrow m => String -> m BaseUrl
5253parseBaseUrl s = case parseURI (removeTrailingSlash s) of
5354 -- This is a rather hacky implementation and should be replaced with something
5455 -- implemented in attoparsec (which is already a dependency anyhow (via aeson)).
55− Just (URI "http:" (Just (URIAuth "" host (':' : (readMaybe -> Just port)))) "" "" "") ->
56− return (BaseUrl Http host port)
57− Just (URI "http:" (Just (URIAuth "" host "")) "" "" "") ->
58− return (BaseUrl Http host 80)
59− Just (URI "https:" (Just (URIAuth "" host (':' : (readMaybe -> Just port)))) "" "" "") ->
60− return (BaseUrl Https host port)
61− Just (URI "https:" (Just (URIAuth "" host "")) "" "" "") ->
62− return (BaseUrl Https host 443)
56+ Just (URI "http:" (Just (URIAuth "" host (':' : (readMaybe -> Just port)))) path "" "") ->
57+ return (BaseUrl Http host port path)
58+ Just (URI "http:" (Just (URIAuth "" host "")) path "" "") ->
59+ return (BaseUrl Http host 80 path)
60+ Just (URI "https:" (Just (URIAuth "" host (':' : (readMaybe -> Just port)))) path "" "") ->
61+ return (BaseUrl Https host port path)
62+ Just (URI "https:" (Just (URIAuth "" host "")) path "" "") ->
63+ return (BaseUrl Https host 443 path)
6364 _ -> if "://" `isInfixOf` s
6465 then throwM (InvalidBaseUrlException $ "Invalid base URL: " ++ s)
6566 else parseBaseUrl ("http://" ++ s)