Skip to content

inferno-vc shouldn't use Manager internals #101

Description

@ngua

mkVCClientEnv in inferno-vc currently uses the internals of Manager (from http-client) to modify request headers and body:

mkVCClientEnv :: Manager -> BaseUrl -> ClientEnv
mkVCClientEnv man@Manager {mModifyRequest = modReq} baseUrl =
mkClientEnv man {mModifyRequest = modReq'} baseUrl
where
modReq' :: Request -> IO Request
modReq' r = do
x <- modReq r
pure $
if ((hContentEncoding, "gzip") `elem` requestHeaders x)
then x
else
let new_hdrs = (hContentEncoding, "gzip") : requestHeaders x
(hrds, body) = case requestBody x of
RequestBodyBuilder _ _ -> (requestHeaders x, requestBody x)
RequestBodyStream _ _ -> (requestHeaders x, requestBody x)
RequestBodyStreamChunked _ -> (requestHeaders x, requestBody x)
b -> (new_hdrs, compressBody b)
in x {requestHeaders = hrds, requestBody = body}
compressBody :: RequestBody -> RequestBody
compressBody = \case
RequestBodyLBS bsl -> RequestBodyLBS $ compress bsl
RequestBodyBS bs -> RequestBodyLBS $ compress $ BSL.fromStrict bs
RequestBodyIO iob -> RequestBodyIO $ compressBody <$> iob
b -> b

I don't think we should rely on the internal implementation of Manager like this; the current docs for that Network.HTTP.Client.Internal state

No API stability is guaranteed for this module

which is generally the case for modules marked as internal.

We could probably just use a middleware to achieve the same thing. Or, if that's not possible, this code should document why it's necessary to use internal modules from another library

Metadata

Metadata

Assignees

No one assigned

    Labels

    correctnessMake something more correct

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions