{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE StandaloneDeriving
-- , GeneralizedNewtypeDeriving
, DeriveGeneric
, DeriveAnyClass
#-}
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
module Uniform.HttpURI (
module Uniform.HttpURI
) where
import qualified Network.URI as N
import Uniform.Json
import UniformBase
newtype URI = URI Text
deriving (Int -> URI -> ShowS
[URI] -> ShowS
URI -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [URI] -> ShowS
$cshowList :: [URI] -> ShowS
show :: URI -> String
$cshow :: URI -> String
showsPrec :: Int -> URI -> ShowS
$cshowsPrec :: Int -> URI -> ShowS
Show, ReadPrec [URI]
ReadPrec URI
Int -> ReadS URI
ReadS [URI]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [URI]
$creadListPrec :: ReadPrec [URI]
readPrec :: ReadPrec URI
$creadPrec :: ReadPrec URI
readList :: ReadS [URI]
$creadList :: ReadS [URI]
readsPrec :: Int -> ReadS URI
$creadsPrec :: Int -> ReadS URI
Read, URI -> URI -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: URI -> URI -> Bool
$c/= :: URI -> URI -> Bool
== :: URI -> URI -> Bool
$c== :: URI -> URI -> Bool
Eq, Eq URI
URI -> URI -> Bool
URI -> URI -> Ordering
URI -> URI -> URI
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
min :: URI -> URI -> URI
$cmin :: URI -> URI -> URI
max :: URI -> URI -> URI
$cmax :: URI -> URI -> URI
>= :: URI -> URI -> Bool
$c>= :: URI -> URI -> Bool
> :: URI -> URI -> Bool
$c> :: URI -> URI -> Bool
<= :: URI -> URI -> Bool
$c<= :: URI -> URI -> Bool
< :: URI -> URI -> Bool
$c< :: URI -> URI -> Bool
compare :: URI -> URI -> Ordering
$ccompare :: URI -> URI -> Ordering
Ord, forall x. Rep URI x -> URI
forall x. URI -> Rep URI x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep URI x -> URI
$cfrom :: forall x. URI -> Rep URI x
Generic, URI
Eq URI => URI -> Bool
forall z.
z -> (Eq z => z -> Bool) -> (Eq z => z -> Bool) -> Zeros z
notZero :: Eq URI => URI -> Bool
$cnotZero :: Eq URI => URI -> Bool
isZero :: Eq URI => URI -> Bool
$cisZero :: Eq URI => URI -> Bool
zero :: URI
$czero :: URI
Zeros)
unURI :: URI -> Text
unURI (URI Text
a) = Text
a
uriT :: URI -> Text
uriT = URI -> Text
unURI
instance ToJSON URI
instance FromJSON URI
instance NiceStrings URI where shownice :: URI -> Text
shownice URI
s = forall a. CharChains a => [a] -> a
unwords' [Text
"URI", URI -> Text
unURI URI
s]
makeURI :: Text -> URI
makeURI :: Text -> URI
makeURI = Text -> URI
parseURI
addToURI :: URI -> Text -> URI
addToURI :: URI -> Text -> URI
addToURI URI
u Text
t = Text -> URI
makeURI forall a b. (a -> b) -> a -> b
$ URI -> Text
uriT URI
u forall a. Semigroup a => a -> a -> a
<> Text
"/" forall a. Semigroup a => a -> a -> a
<> Text
t
newtype ServerURI = ServerURI {ServerURI -> URI
unServerURI :: URI}
deriving (Int -> ServerURI -> ShowS
[ServerURI] -> ShowS
ServerURI -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServerURI] -> ShowS
$cshowList :: [ServerURI] -> ShowS
show :: ServerURI -> String
$cshow :: ServerURI -> String
showsPrec :: Int -> ServerURI -> ShowS
$cshowsPrec :: Int -> ServerURI -> ShowS
Show, ReadPrec [ServerURI]
ReadPrec ServerURI
Int -> ReadS ServerURI
ReadS [ServerURI]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServerURI]
$creadListPrec :: ReadPrec [ServerURI]
readPrec :: ReadPrec ServerURI
$creadPrec :: ReadPrec ServerURI
readList :: ReadS [ServerURI]
$creadList :: ReadS [ServerURI]
readsPrec :: Int -> ReadS ServerURI
$creadsPrec :: Int -> ReadS ServerURI
Read, ServerURI -> ServerURI -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServerURI -> ServerURI -> Bool
$c/= :: ServerURI -> ServerURI -> Bool
== :: ServerURI -> ServerURI -> Bool
$c== :: ServerURI -> ServerURI -> Bool
Eq, Eq ServerURI
ServerURI -> ServerURI -> Bool
ServerURI -> ServerURI -> Ordering
ServerURI -> ServerURI -> ServerURI
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
min :: ServerURI -> ServerURI -> ServerURI
$cmin :: ServerURI -> ServerURI -> ServerURI
max :: ServerURI -> ServerURI -> ServerURI
$cmax :: ServerURI -> ServerURI -> ServerURI
>= :: ServerURI -> ServerURI -> Bool
$c>= :: ServerURI -> ServerURI -> Bool
> :: ServerURI -> ServerURI -> Bool
$c> :: ServerURI -> ServerURI -> Bool
<= :: ServerURI -> ServerURI -> Bool
$c<= :: ServerURI -> ServerURI -> Bool
< :: ServerURI -> ServerURI -> Bool
$c< :: ServerURI -> ServerURI -> Bool
compare :: ServerURI -> ServerURI -> Ordering
$ccompare :: ServerURI -> ServerURI -> Ordering
Ord, forall x. Rep ServerURI x -> ServerURI
forall x. ServerURI -> Rep ServerURI x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ServerURI x -> ServerURI
$cfrom :: forall x. ServerURI -> Rep ServerURI x
Generic, ServerURI
Eq ServerURI => ServerURI -> Bool
forall z.
z -> (Eq z => z -> Bool) -> (Eq z => z -> Bool) -> Zeros z
notZero :: Eq ServerURI => ServerURI -> Bool
$cnotZero :: Eq ServerURI => ServerURI -> Bool
isZero :: Eq ServerURI => ServerURI -> Bool
$cisZero :: Eq ServerURI => ServerURI -> Bool
zero :: ServerURI
$czero :: ServerURI
Zeros, Addr#
NonEmpty ServerURI -> ServerURI
ServerURI -> ServerURI -> ServerURI
forall b. Integral b => b -> ServerURI -> ServerURI
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a. Addr# -> a
noMethodBindingError :: forall a. Addr# -> a
stimes :: forall b. Integral b => b -> ServerURI -> ServerURI
$cstimes :: forall b. Integral b => b -> ServerURI -> ServerURI
sconcat :: NonEmpty ServerURI -> ServerURI
$csconcat :: NonEmpty ServerURI -> ServerURI
$c<> :: ServerURI -> ServerURI -> ServerURI
Semigroup, Semigroup ServerURI
Addr#
ServerURI
[ServerURI] -> ServerURI
ServerURI -> ServerURI -> ServerURI
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. Addr# -> a
noMethodBindingError :: forall a. Addr# -> a
mconcat :: [ServerURI] -> ServerURI
$cmconcat :: [ServerURI] -> ServerURI
mappend :: ServerURI -> ServerURI -> ServerURI
$cmappend :: ServerURI -> ServerURI -> ServerURI
$cmempty :: ServerURI
Monoid
)
mkServerURI :: URI -> ServerURI
mkServerURI = URI -> ServerURI
ServerURI
mkServerURI4text :: Text -> ServerURI
mkServerURI4text = URI -> ServerURI
ServerURI forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> URI
makeURI
newtype HttpPath = HttpPath Text
deriving (Int -> HttpPath -> ShowS
[HttpPath] -> ShowS
HttpPath -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpPath] -> ShowS
$cshowList :: [HttpPath] -> ShowS
show :: HttpPath -> String
$cshow :: HttpPath -> String
showsPrec :: Int -> HttpPath -> ShowS
$cshowsPrec :: Int -> HttpPath -> ShowS
Show, ReadPrec [HttpPath]
ReadPrec HttpPath
Int -> ReadS HttpPath
ReadS [HttpPath]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpPath]
$creadListPrec :: ReadPrec [HttpPath]
readPrec :: ReadPrec HttpPath
$creadPrec :: ReadPrec HttpPath
readList :: ReadS [HttpPath]
$creadList :: ReadS [HttpPath]
readsPrec :: Int -> ReadS HttpPath
$creadsPrec :: Int -> ReadS HttpPath
Read, HttpPath -> HttpPath -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpPath -> HttpPath -> Bool
$c/= :: HttpPath -> HttpPath -> Bool
== :: HttpPath -> HttpPath -> Bool
$c== :: HttpPath -> HttpPath -> Bool
Eq, Eq HttpPath
HttpPath -> HttpPath -> Bool
HttpPath -> HttpPath -> Ordering
HttpPath -> HttpPath -> HttpPath
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
min :: HttpPath -> HttpPath -> HttpPath
$cmin :: HttpPath -> HttpPath -> HttpPath
max :: HttpPath -> HttpPath -> HttpPath
$cmax :: HttpPath -> HttpPath -> HttpPath
>= :: HttpPath -> HttpPath -> Bool
$c>= :: HttpPath -> HttpPath -> Bool
> :: HttpPath -> HttpPath -> Bool
$c> :: HttpPath -> HttpPath -> Bool
<= :: HttpPath -> HttpPath -> Bool
$c<= :: HttpPath -> HttpPath -> Bool
< :: HttpPath -> HttpPath -> Bool
$c< :: HttpPath -> HttpPath -> Bool
compare :: HttpPath -> HttpPath -> Ordering
$ccompare :: HttpPath -> HttpPath -> Ordering
Ord, forall x. Rep HttpPath x -> HttpPath
forall x. HttpPath -> Rep HttpPath x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpPath x -> HttpPath
$cfrom :: forall x. HttpPath -> Rep HttpPath x
Generic, HttpPath
Eq HttpPath => HttpPath -> Bool
forall z.
z -> (Eq z => z -> Bool) -> (Eq z => z -> Bool) -> Zeros z
notZero :: Eq HttpPath => HttpPath -> Bool
$cnotZero :: Eq HttpPath => HttpPath -> Bool
isZero :: Eq HttpPath => HttpPath -> Bool
$cisZero :: Eq HttpPath => HttpPath -> Bool
zero :: HttpPath
$czero :: HttpPath
Zeros)
mkHttpPath :: Text -> HttpPath
mkHttpPath :: Text -> HttpPath
mkHttpPath = Text -> HttpPath
HttpPath
unHttpQueryParams :: HttpQueryParams -> [(Text, Maybe Text)]
mkHttpQueryParams :: [(Text, Maybe Text)] -> HttpQueryParams
newtype HttpQueryParams = HttpQueryParams [(Text, Maybe Text)]
deriving (Int -> HttpQueryParams -> ShowS
[HttpQueryParams] -> ShowS
HttpQueryParams -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpQueryParams] -> ShowS
$cshowList :: [HttpQueryParams] -> ShowS
show :: HttpQueryParams -> String
$cshow :: HttpQueryParams -> String
showsPrec :: Int -> HttpQueryParams -> ShowS
$cshowsPrec :: Int -> HttpQueryParams -> ShowS
Show, ReadPrec [HttpQueryParams]
ReadPrec HttpQueryParams
Int -> ReadS HttpQueryParams
ReadS [HttpQueryParams]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpQueryParams]
$creadListPrec :: ReadPrec [HttpQueryParams]
readPrec :: ReadPrec HttpQueryParams
$creadPrec :: ReadPrec HttpQueryParams
readList :: ReadS [HttpQueryParams]
$creadList :: ReadS [HttpQueryParams]
readsPrec :: Int -> ReadS HttpQueryParams
$creadsPrec :: Int -> ReadS HttpQueryParams
Read, HttpQueryParams -> HttpQueryParams -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpQueryParams -> HttpQueryParams -> Bool
$c/= :: HttpQueryParams -> HttpQueryParams -> Bool
== :: HttpQueryParams -> HttpQueryParams -> Bool
$c== :: HttpQueryParams -> HttpQueryParams -> Bool
Eq, forall x. Rep HttpQueryParams x -> HttpQueryParams
forall x. HttpQueryParams -> Rep HttpQueryParams x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HttpQueryParams x -> HttpQueryParams
$cfrom :: forall x. HttpQueryParams -> Rep HttpQueryParams x
Generic, HttpQueryParams
Eq HttpQueryParams => HttpQueryParams -> Bool
forall z.
z -> (Eq z => z -> Bool) -> (Eq z => z -> Bool) -> Zeros z
notZero :: Eq HttpQueryParams => HttpQueryParams -> Bool
$cnotZero :: Eq HttpQueryParams => HttpQueryParams -> Bool
isZero :: Eq HttpQueryParams => HttpQueryParams -> Bool
$cisZero :: Eq HttpQueryParams => HttpQueryParams -> Bool
zero :: HttpQueryParams
$czero :: HttpQueryParams
Zeros, Addr#
NonEmpty HttpQueryParams -> HttpQueryParams
HttpQueryParams -> HttpQueryParams -> HttpQueryParams
forall b. Integral b => b -> HttpQueryParams -> HttpQueryParams
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a. Addr# -> a
noMethodBindingError :: forall a. Addr# -> a
stimes :: forall b. Integral b => b -> HttpQueryParams -> HttpQueryParams
$cstimes :: forall b. Integral b => b -> HttpQueryParams -> HttpQueryParams
sconcat :: NonEmpty HttpQueryParams -> HttpQueryParams
$csconcat :: NonEmpty HttpQueryParams -> HttpQueryParams
$c<> :: HttpQueryParams -> HttpQueryParams -> HttpQueryParams
Semigroup, Semigroup HttpQueryParams
Addr#
HttpQueryParams
[HttpQueryParams] -> HttpQueryParams
HttpQueryParams -> HttpQueryParams -> HttpQueryParams
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. Addr# -> a
noMethodBindingError :: forall a. Addr# -> a
mconcat :: [HttpQueryParams] -> HttpQueryParams
$cmconcat :: [HttpQueryParams] -> HttpQueryParams
mappend :: HttpQueryParams -> HttpQueryParams -> HttpQueryParams
$cmappend :: HttpQueryParams -> HttpQueryParams -> HttpQueryParams
$cmempty :: HttpQueryParams
Monoid)
unHttpQueryParams :: HttpQueryParams -> [(Text, Maybe Text)]
unHttpQueryParams (HttpQueryParams [(Text, Maybe Text)]
p) = [(Text, Maybe Text)]
p
mkHttpQueryParams :: [(Text, Maybe Text)] -> HttpQueryParams
mkHttpQueryParams = [(Text, Maybe Text)] -> HttpQueryParams
HttpQueryParams
parseURI :: Text -> URI
parseURI :: Text -> URI
parseURI Text
u = Text -> URI
URI forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a}. Show a => a -> Text
showT forall a b. (a -> b) -> a -> b
$ forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. [Text] -> a
errorT [Text
"parseURI in Uniform.HttpURI not acceptable string \n", Text
u, Text
"END of string"])
forall a. a -> a
id
(String -> Maybe URI
N.parseURI forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
t2s forall a b. (a -> b) -> a -> b
$ Text
u )
makeAbsURI :: Text -> URI
makeAbsURI :: Text -> URI
makeAbsURI = Text -> URI
makeURI
newtype PortNumber = PortNumber Int
deriving (PortNumber -> PortNumber -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PortNumber -> PortNumber -> Bool
$c/= :: PortNumber -> PortNumber -> Bool
== :: PortNumber -> PortNumber -> Bool
$c== :: PortNumber -> PortNumber -> Bool
Eq, Eq PortNumber
PortNumber -> PortNumber -> Bool
PortNumber -> PortNumber -> Ordering
PortNumber -> PortNumber -> PortNumber
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
min :: PortNumber -> PortNumber -> PortNumber
$cmin :: PortNumber -> PortNumber -> PortNumber
max :: PortNumber -> PortNumber -> PortNumber
$cmax :: PortNumber -> PortNumber -> PortNumber
>= :: PortNumber -> PortNumber -> Bool
$c>= :: PortNumber -> PortNumber -> Bool
> :: PortNumber -> PortNumber -> Bool
$c> :: PortNumber -> PortNumber -> Bool
<= :: PortNumber -> PortNumber -> Bool
$c<= :: PortNumber -> PortNumber -> Bool
< :: PortNumber -> PortNumber -> Bool
$c< :: PortNumber -> PortNumber -> Bool
compare :: PortNumber -> PortNumber -> Ordering
$ccompare :: PortNumber -> PortNumber -> Ordering
Ord, Int -> PortNumber -> ShowS
[PortNumber] -> ShowS
PortNumber -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PortNumber] -> ShowS
$cshowList :: [PortNumber] -> ShowS
show :: PortNumber -> String
$cshow :: PortNumber -> String
showsPrec :: Int -> PortNumber -> ShowS
$cshowsPrec :: Int -> PortNumber -> ShowS
Show, ReadPrec [PortNumber]
ReadPrec PortNumber
Int -> ReadS PortNumber
ReadS [PortNumber]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PortNumber]
$creadListPrec :: ReadPrec [PortNumber]
readPrec :: ReadPrec PortNumber
$creadPrec :: ReadPrec PortNumber
readList :: ReadS [PortNumber]
$creadList :: ReadS [PortNumber]
readsPrec :: Int -> ReadS PortNumber
$creadsPrec :: Int -> ReadS PortNumber
Read, forall x. Rep PortNumber x -> PortNumber
forall x. PortNumber -> Rep PortNumber x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PortNumber x -> PortNumber
$cfrom :: forall x. PortNumber -> Rep PortNumber x
Generic, PortNumber
Eq PortNumber => PortNumber -> Bool
forall z.
z -> (Eq z => z -> Bool) -> (Eq z => z -> Bool) -> Zeros z
notZero :: Eq PortNumber => PortNumber -> Bool
$cnotZero :: Eq PortNumber => PortNumber -> Bool
isZero :: Eq PortNumber => PortNumber -> Bool
$cisZero :: Eq PortNumber => PortNumber -> Bool
zero :: PortNumber
$czero :: PortNumber
Zeros)
mkPortNumber :: Int -> PortNumber
mkPortNumber Int
i = if Int
i forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& Int
i forall a. Ord a => a -> a -> Bool
< Int
64000 then Int -> PortNumber
PortNumber Int
i
else forall a. [Text] -> a
errorT [Text
"PortNumber out of range", forall {a}. Show a => a -> Text
showT Int
i]
unPortNumber :: PortNumber -> Int
unPortNumber (PortNumber Int
i) = Int
i
addPort2ServerURI :: ServerURI -> PortNumber -> ServerURI
addPort2ServerURI :: ServerURI -> PortNumber -> ServerURI
addPort2ServerURI (ServerURI URI
u) (PortNumber Int
i) = URI -> ServerURI
mkServerURI (Text -> URI
makeURI forall a b. (a -> b) -> a -> b
$ URI -> Text
uriT URI
u Text -> Text -> Text
<:> forall {a}. Show a => a -> Text
showT Int
i)