{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveLift #-}
{-# LANGUAGE ViewPatterns #-}
module Servant.Client.Core.BaseUrl (
BaseUrl (..),
Scheme (..),
showBaseUrl,
parseBaseUrl,
InvalidBaseUrlException (..),
) where
import Control.DeepSeq
(NFData (..))
import Control.Monad.Catch
(Exception, MonadThrow, throwM)
import Data.Aeson
(FromJSON (..), FromJSONKey (..), ToJSON (..), ToJSONKey (..))
import Data.Aeson.Types
(FromJSONKeyFunction (..), contramapToJSONKeyFunction,
withText)
import Data.Data
(Data)
import Data.List
import qualified Data.Text as T
import GHC.Generics
import Language.Haskell.TH.Syntax
(Lift)
import Network.URI hiding
(path)
import Safe
import Text.Read
data Scheme =
Http
| Https
deriving (Int -> Scheme -> ShowS
[Scheme] -> ShowS
Scheme -> String
(Int -> Scheme -> ShowS)
-> (Scheme -> String) -> ([Scheme] -> ShowS) -> Show Scheme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Scheme -> ShowS
showsPrec :: Int -> Scheme -> ShowS
$cshow :: Scheme -> String
show :: Scheme -> String
$cshowList :: [Scheme] -> ShowS
showList :: [Scheme] -> ShowS
Show, Scheme -> Scheme -> Bool
(Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Bool) -> Eq Scheme
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Scheme -> Scheme -> Bool
== :: Scheme -> Scheme -> Bool
$c/= :: Scheme -> Scheme -> Bool
/= :: Scheme -> Scheme -> Bool
Eq, Eq Scheme
Eq Scheme =>
(Scheme -> Scheme -> Ordering)
-> (Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Bool)
-> (Scheme -> Scheme -> Scheme)
-> (Scheme -> Scheme -> Scheme)
-> Ord Scheme
Scheme -> Scheme -> Bool
Scheme -> Scheme -> Ordering
Scheme -> Scheme -> Scheme
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Scheme -> Scheme -> Ordering
compare :: Scheme -> Scheme -> Ordering
$c< :: Scheme -> Scheme -> Bool
< :: Scheme -> Scheme -> Bool
$c<= :: Scheme -> Scheme -> Bool
<= :: Scheme -> Scheme -> Bool
$c> :: Scheme -> Scheme -> Bool
> :: Scheme -> Scheme -> Bool
$c>= :: Scheme -> Scheme -> Bool
>= :: Scheme -> Scheme -> Bool
$cmax :: Scheme -> Scheme -> Scheme
max :: Scheme -> Scheme -> Scheme
$cmin :: Scheme -> Scheme -> Scheme
min :: Scheme -> Scheme -> Scheme
Ord, (forall x. Scheme -> Rep Scheme x)
-> (forall x. Rep Scheme x -> Scheme) -> Generic Scheme
forall x. Rep Scheme x -> Scheme
forall x. Scheme -> Rep Scheme x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Scheme -> Rep Scheme x
from :: forall x. Scheme -> Rep Scheme x
$cto :: forall x. Rep Scheme x -> Scheme
to :: forall x. Rep Scheme x -> Scheme
Generic, (forall (m :: * -> *). Quote m => Scheme -> m Exp)
-> (forall (m :: * -> *). Quote m => Scheme -> Code m Scheme)
-> Lift Scheme
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => Scheme -> m Exp
forall (m :: * -> *). Quote m => Scheme -> Code m Scheme
$clift :: forall (m :: * -> *). Quote m => Scheme -> m Exp
lift :: forall (m :: * -> *). Quote m => Scheme -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => Scheme -> Code m Scheme
liftTyped :: forall (m :: * -> *). Quote m => Scheme -> Code m Scheme
Lift, Typeable Scheme
Typeable Scheme =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Scheme -> c Scheme)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Scheme)
-> (Scheme -> Constr)
-> (Scheme -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Scheme))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Scheme))
-> ((forall b. Data b => b -> b) -> Scheme -> Scheme)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Scheme -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Scheme -> r)
-> (forall u. (forall d. Data d => d -> u) -> Scheme -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Scheme -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme)
-> Data Scheme
Scheme -> Constr
Scheme -> DataType
(forall b. Data b => b -> b) -> Scheme -> Scheme
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Scheme -> u
forall u. (forall d. Data d => d -> u) -> Scheme -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Scheme -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Scheme -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Scheme
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Scheme -> c Scheme
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Scheme)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Scheme)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Scheme -> c Scheme
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Scheme -> c Scheme
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Scheme
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Scheme
$ctoConstr :: Scheme -> Constr
toConstr :: Scheme -> Constr
$cdataTypeOf :: Scheme -> DataType
dataTypeOf :: Scheme -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Scheme)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Scheme)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Scheme)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Scheme)
$cgmapT :: (forall b. Data b => b -> b) -> Scheme -> Scheme
gmapT :: (forall b. Data b => b -> b) -> Scheme -> Scheme
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Scheme -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Scheme -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Scheme -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Scheme -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Scheme -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Scheme -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Scheme -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Scheme -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Scheme -> m Scheme
Data)
data BaseUrl = BaseUrl
{ BaseUrl -> Scheme
baseUrlScheme :: Scheme
, BaseUrl -> String
baseUrlHost :: String
, BaseUrl -> Int
baseUrlPort :: Int
, BaseUrl -> String
baseUrlPath :: String
} deriving (Int -> BaseUrl -> ShowS
[BaseUrl] -> ShowS
BaseUrl -> String
(Int -> BaseUrl -> ShowS)
-> (BaseUrl -> String) -> ([BaseUrl] -> ShowS) -> Show BaseUrl
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BaseUrl -> ShowS
showsPrec :: Int -> BaseUrl -> ShowS
$cshow :: BaseUrl -> String
show :: BaseUrl -> String
$cshowList :: [BaseUrl] -> ShowS
showList :: [BaseUrl] -> ShowS
Show, Eq BaseUrl
Eq BaseUrl =>
(BaseUrl -> BaseUrl -> Ordering)
-> (BaseUrl -> BaseUrl -> Bool)
-> (BaseUrl -> BaseUrl -> Bool)
-> (BaseUrl -> BaseUrl -> Bool)
-> (BaseUrl -> BaseUrl -> Bool)
-> (BaseUrl -> BaseUrl -> BaseUrl)
-> (BaseUrl -> BaseUrl -> BaseUrl)
-> Ord BaseUrl
BaseUrl -> BaseUrl -> Bool
BaseUrl -> BaseUrl -> Ordering
BaseUrl -> BaseUrl -> BaseUrl
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BaseUrl -> BaseUrl -> Ordering
compare :: BaseUrl -> BaseUrl -> Ordering
$c< :: BaseUrl -> BaseUrl -> Bool
< :: BaseUrl -> BaseUrl -> Bool
$c<= :: BaseUrl -> BaseUrl -> Bool
<= :: BaseUrl -> BaseUrl -> Bool
$c> :: BaseUrl -> BaseUrl -> Bool
> :: BaseUrl -> BaseUrl -> Bool
$c>= :: BaseUrl -> BaseUrl -> Bool
>= :: BaseUrl -> BaseUrl -> Bool
$cmax :: BaseUrl -> BaseUrl -> BaseUrl
max :: BaseUrl -> BaseUrl -> BaseUrl
$cmin :: BaseUrl -> BaseUrl -> BaseUrl
min :: BaseUrl -> BaseUrl -> BaseUrl
Ord, (forall x. BaseUrl -> Rep BaseUrl x)
-> (forall x. Rep BaseUrl x -> BaseUrl) -> Generic BaseUrl
forall x. Rep BaseUrl x -> BaseUrl
forall x. BaseUrl -> Rep BaseUrl x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BaseUrl -> Rep BaseUrl x
from :: forall x. BaseUrl -> Rep BaseUrl x
$cto :: forall x. Rep BaseUrl x -> BaseUrl
to :: forall x. Rep BaseUrl x -> BaseUrl
Generic, (forall (m :: * -> *). Quote m => BaseUrl -> m Exp)
-> (forall (m :: * -> *). Quote m => BaseUrl -> Code m BaseUrl)
-> Lift BaseUrl
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => BaseUrl -> m Exp
forall (m :: * -> *). Quote m => BaseUrl -> Code m BaseUrl
$clift :: forall (m :: * -> *). Quote m => BaseUrl -> m Exp
lift :: forall (m :: * -> *). Quote m => BaseUrl -> m Exp
$cliftTyped :: forall (m :: * -> *). Quote m => BaseUrl -> Code m BaseUrl
liftTyped :: forall (m :: * -> *). Quote m => BaseUrl -> Code m BaseUrl
Lift, Typeable BaseUrl
Typeable BaseUrl =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BaseUrl -> c BaseUrl)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BaseUrl)
-> (BaseUrl -> Constr)
-> (BaseUrl -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BaseUrl))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BaseUrl))
-> ((forall b. Data b => b -> b) -> BaseUrl -> BaseUrl)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BaseUrl -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BaseUrl -> r)
-> (forall u. (forall d. Data d => d -> u) -> BaseUrl -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> BaseUrl -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl)
-> Data BaseUrl
BaseUrl -> Constr
BaseUrl -> DataType
(forall b. Data b => b -> b) -> BaseUrl -> BaseUrl
forall a.
Typeable a =>
(forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> BaseUrl -> u
forall u. (forall d. Data d => d -> u) -> BaseUrl -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BaseUrl -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BaseUrl -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BaseUrl
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BaseUrl -> c BaseUrl
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BaseUrl)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BaseUrl)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BaseUrl -> c BaseUrl
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> BaseUrl -> c BaseUrl
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BaseUrl
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c BaseUrl
$ctoConstr :: BaseUrl -> Constr
toConstr :: BaseUrl -> Constr
$cdataTypeOf :: BaseUrl -> DataType
dataTypeOf :: BaseUrl -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BaseUrl)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c BaseUrl)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BaseUrl)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c BaseUrl)
$cgmapT :: (forall b. Data b => b -> b) -> BaseUrl -> BaseUrl
gmapT :: (forall b. Data b => b -> b) -> BaseUrl -> BaseUrl
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BaseUrl -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> BaseUrl -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BaseUrl -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> BaseUrl -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> BaseUrl -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> BaseUrl -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BaseUrl -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> BaseUrl -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> BaseUrl -> m BaseUrl
Data)
instance NFData BaseUrl where
rnf :: BaseUrl -> ()
rnf (BaseUrl Scheme
a String
b Int
c String
d) = Scheme
a Scheme -> () -> ()
forall a b. a -> b -> b
`seq` String -> ()
forall a. NFData a => a -> ()
rnf String
b () -> () -> ()
forall a b. a -> b -> b
`seq` Int -> ()
forall a. NFData a => a -> ()
rnf Int
c () -> () -> ()
forall a b. a -> b -> b
`seq` String -> ()
forall a. NFData a => a -> ()
rnf String
d
instance Eq BaseUrl where
BaseUrl Scheme
a String
b Int
c String
path == :: BaseUrl -> BaseUrl -> Bool
== BaseUrl Scheme
a' String
b' Int
c' String
path'
= Scheme
a Scheme -> Scheme -> Bool
forall a. Eq a => a -> a -> Bool
== Scheme
a' Bool -> Bool -> Bool
&& String
b String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
b' Bool -> Bool -> Bool
&& Int
c Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
c' Bool -> Bool -> Bool
&& ShowS
s String
path String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== ShowS
s String
path'
where s :: ShowS
s (Char
'/':String
x) = String
x
s String
x = String
x
instance ToJSON BaseUrl where
toJSON :: BaseUrl -> Value
toJSON = String -> Value
forall a. ToJSON a => a -> Value
toJSON (String -> Value) -> (BaseUrl -> String) -> BaseUrl -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BaseUrl -> String
showBaseUrl
toEncoding :: BaseUrl -> Encoding
toEncoding = String -> Encoding
forall a. ToJSON a => a -> Encoding
toEncoding (String -> Encoding) -> (BaseUrl -> String) -> BaseUrl -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BaseUrl -> String
showBaseUrl
instance FromJSON BaseUrl where
parseJSON :: Value -> Parser BaseUrl
parseJSON = String -> (Text -> Parser BaseUrl) -> Value -> Parser BaseUrl
forall a. String -> (Text -> Parser a) -> Value -> Parser a
withText String
"BaseUrl" ((Text -> Parser BaseUrl) -> Value -> Parser BaseUrl)
-> (Text -> Parser BaseUrl) -> Value -> Parser BaseUrl
forall a b. (a -> b) -> a -> b
$ \Text
t -> case String -> Maybe BaseUrl
forall (m :: * -> *). MonadThrow m => String -> m BaseUrl
parseBaseUrl (Text -> String
T.unpack Text
t) of
Just BaseUrl
u -> BaseUrl -> Parser BaseUrl
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return BaseUrl
u
Maybe BaseUrl
Nothing -> String -> Parser BaseUrl
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser BaseUrl) -> String -> Parser BaseUrl
forall a b. (a -> b) -> a -> b
$ String
"Invalid base url: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
t
instance ToJSONKey BaseUrl where
toJSONKey :: ToJSONKeyFunction BaseUrl
toJSONKey = (BaseUrl -> String)
-> ToJSONKeyFunction String -> ToJSONKeyFunction BaseUrl
forall b a. (b -> a) -> ToJSONKeyFunction a -> ToJSONKeyFunction b
contramapToJSONKeyFunction BaseUrl -> String
showBaseUrl ToJSONKeyFunction String
forall a. ToJSONKey a => ToJSONKeyFunction a
toJSONKey
instance FromJSONKey BaseUrl where
fromJSONKey :: FromJSONKeyFunction BaseUrl
fromJSONKey = (Text -> Parser BaseUrl) -> FromJSONKeyFunction BaseUrl
forall a. (Text -> Parser a) -> FromJSONKeyFunction a
FromJSONKeyTextParser ((Text -> Parser BaseUrl) -> FromJSONKeyFunction BaseUrl)
-> (Text -> Parser BaseUrl) -> FromJSONKeyFunction BaseUrl
forall a b. (a -> b) -> a -> b
$ \Text
t -> case String -> Maybe BaseUrl
forall (m :: * -> *). MonadThrow m => String -> m BaseUrl
parseBaseUrl (Text -> String
T.unpack Text
t) of
Just BaseUrl
u -> BaseUrl -> Parser BaseUrl
forall a. a -> Parser a
forall (m :: * -> *) a. Monad m => a -> m a
return BaseUrl
u
Maybe BaseUrl
Nothing -> String -> Parser BaseUrl
forall a. String -> Parser a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser BaseUrl) -> String -> Parser BaseUrl
forall a b. (a -> b) -> a -> b
$ String
"Invalid base url: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
T.unpack Text
t
showBaseUrl :: BaseUrl -> String
showBaseUrl :: BaseUrl -> String
showBaseUrl (BaseUrl Scheme
urlscheme String
host Int
port String
path) =
String
schemeString String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"//" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
host String -> ShowS
forall a. [a] -> [a] -> [a]
++ (String
portString String -> ShowS
</> String
path)
where
String
a </> :: String -> ShowS
</> String
b = if String
"/" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
b Bool -> Bool -> Bool
|| String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
b then String
a String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
b else String
a String -> ShowS
forall a. [a] -> [a] -> [a]
++ Char
'/'Char -> ShowS
forall a. a -> [a] -> [a]
:String
b
schemeString :: String
schemeString = case Scheme
urlscheme of
Scheme
Http -> String
"http:"
Scheme
Https -> String
"https:"
portString :: String
portString = case (Scheme
urlscheme, Int
port) of
(Scheme
Http, Int
80) -> String
""
(Scheme
Https, Int
443) -> String
""
(Scheme, Int)
_ -> String
":" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
port
newtype InvalidBaseUrlException = InvalidBaseUrlException String deriving (Int -> InvalidBaseUrlException -> ShowS
[InvalidBaseUrlException] -> ShowS
InvalidBaseUrlException -> String
(Int -> InvalidBaseUrlException -> ShowS)
-> (InvalidBaseUrlException -> String)
-> ([InvalidBaseUrlException] -> ShowS)
-> Show InvalidBaseUrlException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> InvalidBaseUrlException -> ShowS
showsPrec :: Int -> InvalidBaseUrlException -> ShowS
$cshow :: InvalidBaseUrlException -> String
show :: InvalidBaseUrlException -> String
$cshowList :: [InvalidBaseUrlException] -> ShowS
showList :: [InvalidBaseUrlException] -> ShowS
Show)
instance Exception InvalidBaseUrlException
parseBaseUrl :: MonadThrow m => String -> m BaseUrl
parseBaseUrl :: forall (m :: * -> *). MonadThrow m => String -> m BaseUrl
parseBaseUrl String
s = case String -> Maybe URI
parseURI (ShowS
removeTrailingSlash String
s) of
Just (URI String
"http:" (Just (URIAuth String
"" String
host (Char
':' : (String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe -> Just Int
port)))) String
path String
"" String
"") ->
BaseUrl -> m BaseUrl
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Scheme -> String -> Int -> String -> BaseUrl
BaseUrl Scheme
Http String
host Int
port String
path)
Just (URI String
"http:" (Just (URIAuth String
"" String
host String
"")) String
path String
"" String
"") ->
BaseUrl -> m BaseUrl
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Scheme -> String -> Int -> String -> BaseUrl
BaseUrl Scheme
Http String
host Int
80 String
path)
Just (URI String
"https:" (Just (URIAuth String
"" String
host (Char
':' : (String -> Maybe Int
forall a. Read a => String -> Maybe a
readMaybe -> Just Int
port)))) String
path String
"" String
"") ->
BaseUrl -> m BaseUrl
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Scheme -> String -> Int -> String -> BaseUrl
BaseUrl Scheme
Https String
host Int
port String
path)
Just (URI String
"https:" (Just (URIAuth String
"" String
host String
"")) String
path String
"" String
"") ->
BaseUrl -> m BaseUrl
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (Scheme -> String -> Int -> String -> BaseUrl
BaseUrl Scheme
Https String
host Int
443 String
path)
Maybe URI
_ -> if String
"://" String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isInfixOf` String
s
then InvalidBaseUrlException -> m BaseUrl
forall e a. (HasCallStack, Exception e) => e -> m a
forall (m :: * -> *) e a.
(MonadThrow m, HasCallStack, Exception e) =>
e -> m a
throwM (String -> InvalidBaseUrlException
InvalidBaseUrlException (String -> InvalidBaseUrlException)
-> String -> InvalidBaseUrlException
forall a b. (a -> b) -> a -> b
$ String
"Invalid base URL: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s)
else String -> m BaseUrl
forall (m :: * -> *). MonadThrow m => String -> m BaseUrl
parseBaseUrl (String
"http://" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
s)
where
removeTrailingSlash :: ShowS
removeTrailingSlash String
str = case String -> Maybe Char
forall a. [a] -> Maybe a
lastMay String
str of
Just Char
'/' -> ShowS
forall a. HasCallStack => [a] -> [a]
init String
str
Maybe Char
_ -> String
str