on master help sign in
Adds requests builder
commitf3e8cc8ede3c9f457fcafcf66fc8c0225dead699 authorDeni Bertovic <deni@denibertovic.com> dateThu 10 Mar 2016, 16:09 (11 years ago) parentfa2bd89
2 files changed+23−4
src/Docker/Internal.hs+19−3 src/Docker/Types.hs+4−1
src/Docker/Internal.hs+19−3
@@ -4,17 +4,33 @@ module Docker.Internal where
44import Blaze.ByteString.Builder (toByteString)
55import Data.ByteString as BS
66import Data.ByteString (ByteString)
7+import Data.Maybe
78import Data.Text as T
89import Data.Text (Text)
910import Data.Text.Encoding (decodeUtf8, encodeUtf8)
11+import qualified Network.HTTP.Client as HTTP
1012import Network.HTTP.Types (Query, encodePath,
1113 encodePathSegments)
1214
13−
1415import Docker.Types
1516
16−mkHttpRequest :: DockerClientOpts -> Request
17−mkHttpRequest = undefined
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.
22+mkHttpRequest :: HttpVerb -> Endpoint -> DockerClientOpts -> Maybe Request
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
1834
1935encodeURL :: [Text] -> Text
2036encodeURL ps = decodeUtf8 $ toByteString $ encodePathSegments ps
src/Docker/Types.hs+4−1
@@ -15,6 +15,9 @@ import Data.Text (Text)
1515import qualified Data.Text as T
1616import GHC.Generics (Generic)
1717import qualified Network.HTTP.Client as HTTP
18+import Network.HTTP.Types (StdMethod)
19+
20+type HttpVerb = StdMethod
1821
1922data Endpoint =
2023 VersionEndpoint
@@ -59,7 +62,7 @@ data ListOpts = ListOpts { all :: Bool } deriving (Eq, Show)
5962defaultClientOpts :: DockerClientOpts
6063defaultClientOpts = DockerClientOpts {
6164 apiVer = "v1.22"
62− , baseUrl = "http://127.0.0.1:2375/"
65+ , baseUrl = "http://127.0.0.1:2375"
6366 }
6467
6568data DockerVersion = DockerVersion {