renamed Request to GemURL
- A request should contain a URL and an optional client certigicate. - renamed accompanying functions accordingly
This commit is contained in:
@@ -27,7 +27,7 @@ License along with this program. If not, see
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
|
||||
module Network.GemServ (
|
||||
encodeRequest,
|
||||
encodeGemURL,
|
||||
escapeString,
|
||||
unescapeString
|
||||
) where
|
||||
@@ -43,16 +43,16 @@ import Data.Text.Encoding (decodeUtf8')
|
||||
|
||||
import Network.GemServ.Types
|
||||
|
||||
-- | Encodes a 'Request' into a 'String'
|
||||
encodeRequest :: Request -> String
|
||||
encodeRequest req =
|
||||
-- | Encodes a 'GemURL' into a 'String'
|
||||
encodeGemURL :: GemURL -> String
|
||||
encodeGemURL url =
|
||||
"gemini://" ++ authority ++ "/" ++ path ++ query
|
||||
where
|
||||
authority = reqHost req ++ case reqPort req of
|
||||
authority = gemHost url ++ case gemPort url of
|
||||
Just port -> ':' : show port
|
||||
Nothing -> ""
|
||||
path = intercalate "/" $ map escapeString $ reqPath req
|
||||
query = case reqQuery req of
|
||||
path = intercalate "/" $ map escapeString $ gemPath url
|
||||
query = case gemQuery url of
|
||||
"" -> ""
|
||||
q -> '?' : escapeString q
|
||||
|
||||
|
||||
@@ -25,34 +25,34 @@ License along with this program. If not, see
|
||||
-}
|
||||
|
||||
module Network.GemServ.Types (
|
||||
Request (..),
|
||||
newRequest
|
||||
GemURL (..),
|
||||
newGemURL
|
||||
) where
|
||||
|
||||
import Data.Word (Word32)
|
||||
|
||||
-- | Gemini request
|
||||
data Request = Request
|
||||
{ reqHost :: String
|
||||
-- | Gemini URL
|
||||
data GemURL = GemURL
|
||||
{ gemHost :: String
|
||||
-- ^ The host part of the authority section, e.g.: "example.com"
|
||||
, reqPort :: Maybe Word32
|
||||
, gemPort :: Maybe Word32
|
||||
-- ^ The port number (if supplied)
|
||||
, reqPath :: [String]
|
||||
, gemPath :: [String]
|
||||
-- ^ The decoded path segments
|
||||
, reqQuery :: String
|
||||
, gemQuery :: String
|
||||
-- ^ The decoded request query
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | Builds a new request
|
||||
newRequest
|
||||
-- | Builds a new 'GemURL'
|
||||
newGemURL
|
||||
:: String
|
||||
-- ^ The hostname
|
||||
-> Request
|
||||
newRequest host = Request
|
||||
{ reqHost = host
|
||||
, reqPort = Nothing
|
||||
, reqPath = []
|
||||
, reqQuery = ""
|
||||
-> GemURL
|
||||
newGemURL host = GemURL
|
||||
{ gemHost = host
|
||||
, gemPort = Nothing
|
||||
, gemPath = []
|
||||
, gemQuery = ""
|
||||
}
|
||||
|
||||
--jl
|
||||
|
||||
Reference in New Issue
Block a user