Adds requests builder

This commit is contained in:
Deni Bertovic 2016-03-10 16:09:55 +01:00
parent fa2bd89cf5
commit f3e8cc8ede
2 changed files with 23 additions and 4 deletions

View File

@ -4,17 +4,33 @@ module Docker.Internal where
import Blaze.ByteString.Builder (toByteString)
import Data.ByteString as BS
import Data.ByteString (ByteString)
import Data.Maybe
import Data.Text as T
import Data.Text (Text)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import qualified Network.HTTP.Client as HTTP
import Network.HTTP.Types (Query, encodePath,
encodePathSegments)
import Docker.Types
mkHttpRequest :: DockerClientOpts -> Request
mkHttpRequest = undefined
-- The reason we return Maybe Request is because the parseURL function
-- might find out parameters are invalid and will fail to build a Request
-- Since we're building the Requests this shouldn't happen, but would
-- benefit from testing that for instance all of our Endpoints are solid
-- and so on.
mkHttpRequest :: HttpVerb -> Endpoint -> DockerClientOpts -> Maybe Request
mkHttpRequest verb e opts = request
where fullE = T.unpack (baseUrl opts) ++ T.unpack (getEndpoint e)
initialR = HTTP.parseUrl fullE
request = case initialR of
Just ir -> return $ ir { HTTP.method = (encodeUtf8 . T.pack $ show verb) } -- , requestBody = RequestBodyLBS $ encode requestObject }
Nothing -> Nothing
-- TODO: manager = newManager defaultManagerSettings -- We likely need
-- this for TLS.
defaultHandler :: Request -> IO Response
defaultHandler = undefined
encodeURL :: [Text] -> Text
encodeURL ps = decodeUtf8 $ toByteString $ encodePathSegments ps

View File

@ -15,6 +15,9 @@ import Data.Text (Text)
import qualified Data.Text as T
import GHC.Generics (Generic)
import qualified Network.HTTP.Client as HTTP
import Network.HTTP.Types (StdMethod)
type HttpVerb = StdMethod
data Endpoint =
VersionEndpoint
@ -59,7 +62,7 @@ data ListOpts = ListOpts { all :: Bool } deriving (Eq, Show)
defaultClientOpts :: DockerClientOpts
defaultClientOpts = DockerClientOpts {
apiVer = "v1.22"
, baseUrl = "http://127.0.0.1:2375/"
, baseUrl = "http://127.0.0.1:2375"
}
data DockerVersion = DockerVersion {