on master help sign in
Adds requests builder
f3e8cc8Deni Bertovic
src/Docker/Internal.hs+19−3
@@ -4,17 +4,33 @@ module Docker.Internal where
4import Blaze.ByteString.Builder (toByteString)
4import Blaze.ByteString.Builder (toByteString)
5import Data.ByteString as BS
5import Data.ByteString as BS
6import Data.ByteString (ByteString)
6import Data.ByteString (ByteString)
7+import Data.Maybe
7import Data.Text as T
8import Data.Text as T
8import Data.Text (Text)
9import Data.Text (Text)
9import Data.Text.Encoding (decodeUtf8, encodeUtf8)
10import Data.Text.Encoding (decodeUtf8, encodeUtf8)
11+import qualified Network.HTTP.Client as HTTP
10import Network.HTTP.Types (Query, encodePath,
12import Network.HTTP.Types (Query, encodePath,
11 encodePathSegments)
13 encodePathSegments)
12
14
13−
14import Docker.Types
15import Docker.Types
15
16
17+-- The reason we return Maybe Request is because the parseURL function
18+-- might find out parameters are invalid and will fail to build a Request
19+-- Since we're building the Requests this shouldn't happen, but would
20+-- benefit from testing that for instance all of our Endpoints are solid
21+-- and so on.
16−mkHttpRequest :: DockerClientOpts -> Request
22+mkHttpRequest :: HttpVerb -> Endpoint -> DockerClientOpts -> Maybe Request
17−mkHttpRequest = undefined
23+mkHttpRequest verb e opts = request
24+ where fullE = T.unpack (baseUrl opts) ++ T.unpack (getEndpoint e)
25+ initialR = HTTP.parseUrl fullE
26+ request = case initialR of
27+ Just ir -> return $ ir { HTTP.method = (encodeUtf8 . T.pack $ show verb) } -- , requestBody = RequestBodyLBS $ encode requestObject }
28+ Nothing -> Nothing
29+ -- TODO: manager = newManager defaultManagerSettings -- We likely need
30+ -- this for TLS.
31+
32+defaultHandler :: Request -> IO Response
33+defaultHandler = undefined
18
34
19encodeURL :: [Text] -> Text
35encodeURL :: [Text] -> Text
20encodeURL ps = decodeUtf8 $ toByteString $ encodePathSegments ps
36encodeURL ps = decodeUtf8 $ toByteString $ encodePathSegments ps
src/Docker/Types.hs+4−1
@@ -15,6 +15,9 @@ import Data.Text (Text)
15import qualified Data.Text as T
15import qualified Data.Text as T
16import GHC.Generics (Generic)
16import GHC.Generics (Generic)
17import qualified Network.HTTP.Client as HTTP
17import qualified Network.HTTP.Client as HTTP
18+import Network.HTTP.Types (StdMethod)
19+
20+type HttpVerb = StdMethod
18
21
19data Endpoint =
22data Endpoint =
20 VersionEndpoint
23 VersionEndpoint
@@ -59,7 +62,7 @@ data ListOpts = ListOpts { all :: Bool } deriving (Eq, Show)
59defaultClientOpts :: DockerClientOpts
62defaultClientOpts :: DockerClientOpts
60defaultClientOpts = DockerClientOpts {
63defaultClientOpts = DockerClientOpts {
61 apiVer = "v1.22"
64 apiVer = "v1.22"
62− , baseUrl = "http://127.0.0.1:2375/"
65+ , baseUrl = "http://127.0.0.1:2375"
63 }
66 }
64
67
65data DockerVersion = DockerVersion {
68data DockerVersion = DockerVersion {