@@ -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