Search code examples
haskellhttp-conduit

defaultManagerSettings not in scope in Network.HTTP.Conduit


In http-conduit version 2.0+ I want to create a custom Manager.

The documentation states that defaultManagerSettings should be used in newManager.

import Network.HTTP.Conduit
main = do manager <- newManager defaultManagerSettings
          print $ content

However, when trying to run it I get the following error:

conduittest.hs:3:33:
    Not in scope: `defaultManagerSettings'
    Perhaps you meant `conduitManagerSettings' (imported from Network.HTTP.Conduit)

Shall I use conduitManagerSettings instead? If not, where can I import defaultManagerSettings from?

Note: This question intentionally does not show further research effort, because it was immediately answered in a Q&A-style manner.


Solution

  • As listed in the newManager docs, you can import defaultManagerSettings like this:

    import Network.HTTP.Client (defaultManagerSettings)
    

    Let's have a look what conduitManagerSettings is:

    conduitManagerSettings :: ManagerSettings
    conduitManagerSettings = tlsManagerSettings
    

    In Network.HTTP.Client.TLS, tlsManagerSettings is defined as follows:

    tlsManagerSettings :: ManagerSettings
    tlsManagerSettings = mkManagerSettings def Nothing
    

    Ok, so nothing special here. def is from the Data.Default module and therefore defines the default instance. However defaultManagerSettings specifies all default values.

    I wasn't able to track down where the instance Default ManagerSettings resides. However I think it is safe to assume that mkManagerSettings def Nothing has the same settings as defaultManagerSettings.

    I personally recommend to use defaultManagerSettings, because any of these behaviours might change in the future.