From a2d8f1a5eafdab77dca123c602a37b1595d57b97 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Sun, 24 Oct 2021 15:43:29 -0400 Subject: [PATCH] renamed Request to GemURL - A request should contain a URL and an optional client certigicate. - renamed accompanying functions accordingly --- src/Network/GemServ.hs | 14 +++++++------- src/Network/GemServ/Types.hs | 32 ++++++++++++++++---------------- test/Network/GemServSpec.hs | 32 ++++++++++++++++---------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Network/GemServ.hs b/src/Network/GemServ.hs index 0980419..0432e23 100644 --- a/src/Network/GemServ.hs +++ b/src/Network/GemServ.hs @@ -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 diff --git a/src/Network/GemServ/Types.hs b/src/Network/GemServ/Types.hs index 21c0c63..32dac17 100644 --- a/src/Network/GemServ/Types.hs +++ b/src/Network/GemServ/Types.hs @@ -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 diff --git a/test/Network/GemServSpec.hs b/test/Network/GemServSpec.hs index 0c6807a..a20ad60 100644 --- a/test/Network/GemServSpec.hs +++ b/test/Network/GemServSpec.hs @@ -29,38 +29,38 @@ import Network.GemServ.Types spec :: Spec spec = describe "Network.GemServ" $ do - encodeRequestSpec + encodeGemURLSpec escapeStringSpec unescapeStringSpec -encodeRequestSpec :: Spec -encodeRequestSpec = describe "encodeRequest" $ mapM_ +encodeGemURLSpec :: Spec +encodeGemURLSpec = describe "encodeGemURL" $ mapM_ ( \(desc, req, expected) -> context desc $ it ("should be " ++ show expected) $ - encodeRequest req `shouldBe` expected + encodeGemURL req `shouldBe` expected ) -- description, request, expected - [ ( "simple", simpleReq, simpleExp ) - , ( "with port", withPortReq, withPortExp ) - , ( "with path", withPathReq, withPathExp ) - , ( "with query", withQueryReq, withQueryExp ) - , ( "with escape", withEscapeReq, withEscapeExp ) + [ ( "simple", simpleURL, simpleExp ) + , ( "with port", withPortURL, withPortExp ) + , ( "with path", withPathURL, withPathExp ) + , ( "with query", withQueryURL, withQueryExp ) + , ( "with escape", withEscapeURL, withEscapeExp ) ] where - simpleReq = newRequest "example.com" + simpleURL = newGemURL "example.com" simpleExp = "gemini://example.com/" - withPortReq = simpleReq { reqPort = Just 1965 } + withPortURL = simpleURL { gemPort = Just 1965 } withPortExp = "gemini://example.com:1965/" - withPathReq = simpleReq { reqPath = ["foo", "bar"] } + withPathURL = simpleURL { gemPath = ["foo", "bar"] } withPathExp = "gemini://example.com/foo/bar" - withQueryReq = simpleReq { reqQuery = "foo" } + withQueryURL = simpleURL { gemQuery = "foo" } withQueryExp = "gemini://example.com/?foo" - withEscapeReq = simpleReq - { reqPath = ["foo bar"] - , reqQuery = "baz quux" + withEscapeURL = simpleURL + { gemPath = ["foo bar"] + , gemQuery = "baz quux" } withEscapeExp = "gemini://example.com/foo%20bar?baz%20quux"