{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

A 'GI.Soup.Structs.ClientContext.ClientContext' provides additional information about the
client making a particular request. In particular, you can use
'GI.Soup.Structs.ClientContext.clientContextGetAuthDomain' and
'GI.Soup.Structs.ClientContext.clientContextGetAuthUser' to determine if HTTP
authentication was used successfully.

'GI.Soup.Structs.ClientContext.clientContextGetRemoteAddress' and\/or
'GI.Soup.Structs.ClientContext.clientContextGetHost' can be used to get information for
logging or debugging purposes. 'GI.Soup.Structs.ClientContext.clientContextGetGsocket' may
also be of use in some situations (eg, tracking when multiple
requests are made on the same connection).
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Soup.Structs.ClientContext
    (

-- * Exported types
    ClientContext(..)                       ,
    noClientContext                         ,


 -- * Methods
-- ** getAddress #method:getAddress#

#if ENABLE_OVERLOADING
    ClientContextGetAddressMethodInfo       ,
#endif
    clientContextGetAddress                 ,


-- ** getAuthDomain #method:getAuthDomain#

#if ENABLE_OVERLOADING
    ClientContextGetAuthDomainMethodInfo    ,
#endif
    clientContextGetAuthDomain              ,


-- ** getAuthUser #method:getAuthUser#

#if ENABLE_OVERLOADING
    ClientContextGetAuthUserMethodInfo      ,
#endif
    clientContextGetAuthUser                ,


-- ** getGsocket #method:getGsocket#

#if ENABLE_OVERLOADING
    ClientContextGetGsocketMethodInfo       ,
#endif
    clientContextGetGsocket                 ,


-- ** getHost #method:getHost#

#if ENABLE_OVERLOADING
    ClientContextGetHostMethodInfo          ,
#endif
    clientContextGetHost                    ,


-- ** getLocalAddress #method:getLocalAddress#

#if ENABLE_OVERLOADING
    ClientContextGetLocalAddressMethodInfo  ,
#endif
    clientContextGetLocalAddress            ,


-- ** getRemoteAddress #method:getRemoteAddress#

#if ENABLE_OVERLOADING
    ClientContextGetRemoteAddressMethodInfo ,
#endif
    clientContextGetRemoteAddress           ,


-- ** getSocket #method:getSocket#

#if ENABLE_OVERLOADING
    ClientContextGetSocketMethodInfo        ,
#endif
    clientContextGetSocket                  ,


-- ** stealConnection #method:stealConnection#

#if ENABLE_OVERLOADING
    ClientContextStealConnectionMethodInfo  ,
#endif
    clientContextStealConnection            ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.Gio.Objects.IOStream as Gio.IOStream
import qualified GI.Gio.Objects.Socket as Gio.Socket
import qualified GI.Gio.Objects.SocketAddress as Gio.SocketAddress
import {-# SOURCE #-} qualified GI.Soup.Objects.Address as Soup.Address
import {-# SOURCE #-} qualified GI.Soup.Objects.AuthDomain as Soup.AuthDomain
import {-# SOURCE #-} qualified GI.Soup.Objects.Socket as Soup.Socket

-- | Memory-managed wrapper type.
newtype ClientContext = ClientContext (ManagedPtr ClientContext)
foreign import ccall "soup_client_context_get_type" c_soup_client_context_get_type ::
    IO GType

instance BoxedObject ClientContext where
    boxedType _ = c_soup_client_context_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `ClientContext`.
noClientContext :: Maybe ClientContext
noClientContext = Nothing


#if ENABLE_OVERLOADING
instance O.HasAttributeList ClientContext
type instance O.AttributeList ClientContext = ClientContextAttributeList
type ClientContextAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method ClientContext::get_address
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "client", argType = TInterface (Name {namespace = "Soup", name = "ClientContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupClientContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Address"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_address" soup_client_context_get_address ::
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Soup.Address.Address)

{-# DEPRECATED clientContextGetAddress ["Use 'GI.Soup.Structs.ClientContext.clientContextGetRemoteAddress', which returns","a 'GI.Gio.Objects.SocketAddress.SocketAddress'."] #-}
{- |
Retrieves the 'GI.Soup.Objects.Address.Address' associated with the remote end
of a connection.
-}
clientContextGetAddress ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    {- ^ /@client@/: a 'GI.Soup.Structs.ClientContext.ClientContext' -}
    -> m (Maybe Soup.Address.Address)
    {- ^ __Returns:__ the 'GI.Soup.Objects.Address.Address'
associated with the remote end of a connection, it may be
'Nothing' if you used 'GI.Soup.Objects.Server.serverAcceptIostream'. -}
clientContextGetAddress client = liftIO $ do
    client' <- unsafeManagedPtrGetPtr client
    result <- soup_client_context_get_address client'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newObject Soup.Address.Address) result'
        return result''
    touchManagedPtr client
    return maybeResult

#if ENABLE_OVERLOADING
data ClientContextGetAddressMethodInfo
instance (signature ~ (m (Maybe Soup.Address.Address)), MonadIO m) => O.MethodInfo ClientContextGetAddressMethodInfo ClientContext signature where
    overloadedMethod _ = clientContextGetAddress

#endif

-- method ClientContext::get_auth_domain
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "client", argType = TInterface (Name {namespace = "Soup", name = "ClientContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupClientContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "AuthDomain"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_auth_domain" soup_client_context_get_auth_domain ::
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Soup.AuthDomain.AuthDomain)

{- |
Checks whether the request associated with /@client@/ has been
authenticated, and if so returns the 'GI.Soup.Objects.AuthDomain.AuthDomain' that
authenticated it.
-}
clientContextGetAuthDomain ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    {- ^ /@client@/: a 'GI.Soup.Structs.ClientContext.ClientContext' -}
    -> m (Maybe Soup.AuthDomain.AuthDomain)
    {- ^ __Returns:__ a 'GI.Soup.Objects.AuthDomain.AuthDomain', or
'Nothing' if the request was not authenticated. -}
clientContextGetAuthDomain client = liftIO $ do
    client' <- unsafeManagedPtrGetPtr client
    result <- soup_client_context_get_auth_domain client'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newObject Soup.AuthDomain.AuthDomain) result'
        return result''
    touchManagedPtr client
    return maybeResult

#if ENABLE_OVERLOADING
data ClientContextGetAuthDomainMethodInfo
instance (signature ~ (m (Maybe Soup.AuthDomain.AuthDomain)), MonadIO m) => O.MethodInfo ClientContextGetAuthDomainMethodInfo ClientContext signature where
    overloadedMethod _ = clientContextGetAuthDomain

#endif

-- method ClientContext::get_auth_user
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "client", argType = TInterface (Name {namespace = "Soup", name = "ClientContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupClientContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_auth_user" soup_client_context_get_auth_user ::
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO CString

{- |
Checks whether the request associated with /@client@/ has been
authenticated, and if so returns the username that the client
authenticated as.
-}
clientContextGetAuthUser ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    {- ^ /@client@/: a 'GI.Soup.Structs.ClientContext.ClientContext' -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the authenticated-as user, or 'Nothing' if
the request was not authenticated. -}
clientContextGetAuthUser client = liftIO $ do
    client' <- unsafeManagedPtrGetPtr client
    result <- soup_client_context_get_auth_user client'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr client
    return maybeResult

#if ENABLE_OVERLOADING
data ClientContextGetAuthUserMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo ClientContextGetAuthUserMethodInfo ClientContext signature where
    overloadedMethod _ = clientContextGetAuthUser

#endif

-- method ClientContext::get_gsocket
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "client", argType = TInterface (Name {namespace = "Soup", name = "ClientContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupClientContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "Socket"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_gsocket" soup_client_context_get_gsocket ::
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Gio.Socket.Socket)

{- |
Retrieves the 'GI.Gio.Objects.Socket.Socket' that /@client@/ is associated with.

If you are using this method to observe when multiple requests are
made on the same persistent HTTP connection (eg, as the ntlm-test
test program does), you will need to pay attention to socket
destruction as well (eg, by using weak references), so that you do
not get fooled when the allocator reuses the memory address of a
previously-destroyed socket to represent a new socket.

/Since: 2.48/
-}
clientContextGetGsocket ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    {- ^ /@client@/: a 'GI.Soup.Structs.ClientContext.ClientContext' -}
    -> m (Maybe Gio.Socket.Socket)
    {- ^ __Returns:__ the 'GI.Gio.Objects.Socket.Socket' that /@client@/ is
associated with, 'Nothing' if you used 'GI.Soup.Objects.Server.serverAcceptIostream'. -}
clientContextGetGsocket client = liftIO $ do
    client' <- unsafeManagedPtrGetPtr client
    result <- soup_client_context_get_gsocket client'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newObject Gio.Socket.Socket) result'
        return result''
    touchManagedPtr client
    return maybeResult

#if ENABLE_OVERLOADING
data ClientContextGetGsocketMethodInfo
instance (signature ~ (m (Maybe Gio.Socket.Socket)), MonadIO m) => O.MethodInfo ClientContextGetGsocketMethodInfo ClientContext signature where
    overloadedMethod _ = clientContextGetGsocket

#endif

-- method ClientContext::get_host
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "client", argType = TInterface (Name {namespace = "Soup", name = "ClientContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupClientContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUTF8)
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_host" soup_client_context_get_host ::
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO CString

{- |
Retrieves the IP address associated with the remote end of a
connection.
-}
clientContextGetHost ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    {- ^ /@client@/: a 'GI.Soup.Structs.ClientContext.ClientContext' -}
    -> m (Maybe T.Text)
    {- ^ __Returns:__ the IP address associated with the remote
end of a connection, it may be 'Nothing' if you used
'GI.Soup.Objects.Server.serverAcceptIostream'. -}
clientContextGetHost client = liftIO $ do
    client' <- unsafeManagedPtrGetPtr client
    result <- soup_client_context_get_host client'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- cstringToText result'
        return result''
    touchManagedPtr client
    return maybeResult

#if ENABLE_OVERLOADING
data ClientContextGetHostMethodInfo
instance (signature ~ (m (Maybe T.Text)), MonadIO m) => O.MethodInfo ClientContextGetHostMethodInfo ClientContext signature where
    overloadedMethod _ = clientContextGetHost

#endif

-- method ClientContext::get_local_address
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "client", argType = TInterface (Name {namespace = "Soup", name = "ClientContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupClientContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "SocketAddress"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_local_address" soup_client_context_get_local_address ::
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Gio.SocketAddress.SocketAddress)

{- |
Retrieves the 'GI.Gio.Objects.SocketAddress.SocketAddress' associated with the local end
of a connection.

/Since: 2.48/
-}
clientContextGetLocalAddress ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    {- ^ /@client@/: a 'GI.Soup.Structs.ClientContext.ClientContext' -}
    -> m (Maybe Gio.SocketAddress.SocketAddress)
    {- ^ __Returns:__ the 'GI.Gio.Objects.SocketAddress.SocketAddress'
associated with the local end of a connection, it may be
'Nothing' if you used 'GI.Soup.Objects.Server.serverAcceptIostream'. -}
clientContextGetLocalAddress client = liftIO $ do
    client' <- unsafeManagedPtrGetPtr client
    result <- soup_client_context_get_local_address client'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newObject Gio.SocketAddress.SocketAddress) result'
        return result''
    touchManagedPtr client
    return maybeResult

#if ENABLE_OVERLOADING
data ClientContextGetLocalAddressMethodInfo
instance (signature ~ (m (Maybe Gio.SocketAddress.SocketAddress)), MonadIO m) => O.MethodInfo ClientContextGetLocalAddressMethodInfo ClientContext signature where
    overloadedMethod _ = clientContextGetLocalAddress

#endif

-- method ClientContext::get_remote_address
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "client", argType = TInterface (Name {namespace = "Soup", name = "ClientContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupClientContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "SocketAddress"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_remote_address" soup_client_context_get_remote_address ::
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Gio.SocketAddress.SocketAddress)

{- |
Retrieves the 'GI.Gio.Objects.SocketAddress.SocketAddress' associated with the remote end
of a connection.

/Since: 2.48/
-}
clientContextGetRemoteAddress ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    {- ^ /@client@/: a 'GI.Soup.Structs.ClientContext.ClientContext' -}
    -> m (Maybe Gio.SocketAddress.SocketAddress)
    {- ^ __Returns:__ the 'GI.Gio.Objects.SocketAddress.SocketAddress'
associated with the remote end of a connection, it may be
'Nothing' if you used 'GI.Soup.Objects.Server.serverAcceptIostream'. -}
clientContextGetRemoteAddress client = liftIO $ do
    client' <- unsafeManagedPtrGetPtr client
    result <- soup_client_context_get_remote_address client'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (newObject Gio.SocketAddress.SocketAddress) result'
        return result''
    touchManagedPtr client
    return maybeResult

#if ENABLE_OVERLOADING
data ClientContextGetRemoteAddressMethodInfo
instance (signature ~ (m (Maybe Gio.SocketAddress.SocketAddress)), MonadIO m) => O.MethodInfo ClientContextGetRemoteAddressMethodInfo ClientContext signature where
    overloadedMethod _ = clientContextGetRemoteAddress

#endif

-- method ClientContext::get_socket
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "client", argType = TInterface (Name {namespace = "Soup", name = "ClientContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupClientContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Socket"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_get_socket" soup_client_context_get_socket ::
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Soup.Socket.Socket)

{-# DEPRECATED clientContextGetSocket ["use 'GI.Soup.Structs.ClientContext.clientContextGetGsocket', which returns","a 'GI.Gio.Objects.Socket.Socket'."] #-}
{- |
Retrieves the 'GI.Soup.Objects.Socket.Socket' that /@client@/ is associated with.

If you are using this method to observe when multiple requests are
made on the same persistent HTTP connection (eg, as the ntlm-test
test program does), you will need to pay attention to socket
destruction as well (either by using weak references, or by
connecting to the 'GI.Soup.Objects.Socket.Socket'::@/disconnected/@ signal), so that you do
not get fooled when the allocator reuses the memory address of a
previously-destroyed socket to represent a new socket.
-}
clientContextGetSocket ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    {- ^ /@client@/: a 'GI.Soup.Structs.ClientContext.ClientContext' -}
    -> m Soup.Socket.Socket
    {- ^ __Returns:__ the 'GI.Soup.Objects.Socket.Socket' that /@client@/ is
associated with. -}
clientContextGetSocket client = liftIO $ do
    client' <- unsafeManagedPtrGetPtr client
    result <- soup_client_context_get_socket client'
    checkUnexpectedReturnNULL "clientContextGetSocket" result
    result' <- (newObject Soup.Socket.Socket) result
    touchManagedPtr client
    return result'

#if ENABLE_OVERLOADING
data ClientContextGetSocketMethodInfo
instance (signature ~ (m Soup.Socket.Socket), MonadIO m) => O.MethodInfo ClientContextGetSocketMethodInfo ClientContext signature where
    overloadedMethod _ = clientContextGetSocket

#endif

-- method ClientContext::steal_connection
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "client", argType = TInterface (Name {namespace = "Soup", name = "ClientContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupClientContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "IOStream"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_client_context_steal_connection" soup_client_context_steal_connection ::
    Ptr ClientContext ->                    -- client : TInterface (Name {namespace = "Soup", name = "ClientContext"})
    IO (Ptr Gio.IOStream.IOStream)

{- |
\"Steals\" the HTTP connection associated with /@client@/ from its
'GI.Soup.Objects.Server.Server'. This happens immediately, regardless of the current
state of the connection; if the response to the current
'GI.Soup.Objects.Message.Message' has not yet finished being sent, then it will be
discarded; you can steal the connection from a
'GI.Soup.Objects.Message.Message':@/wrote-informational/@ or 'GI.Soup.Objects.Message.Message':@/wrote-body/@ signal
handler if you need to wait for part or all of the response to be
sent.

Note that when calling this function from C, /@client@/ will most
likely be freed as a side effect.

/Since: 2.50/
-}
clientContextStealConnection ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    ClientContext
    {- ^ /@client@/: a 'GI.Soup.Structs.ClientContext.ClientContext' -}
    -> m Gio.IOStream.IOStream
    {- ^ __Returns:__ the 'GI.Gio.Objects.IOStream.IOStream' formerly associated
  with /@client@/ (or 'Nothing' if /@client@/ was no longer associated with a
  connection). No guarantees are made about what kind of 'GI.Gio.Objects.IOStream.IOStream'
  is returned. -}
clientContextStealConnection client = liftIO $ do
    client' <- unsafeManagedPtrGetPtr client
    result <- soup_client_context_steal_connection client'
    checkUnexpectedReturnNULL "clientContextStealConnection" result
    result' <- (wrapObject Gio.IOStream.IOStream) result
    touchManagedPtr client
    return result'

#if ENABLE_OVERLOADING
data ClientContextStealConnectionMethodInfo
instance (signature ~ (m Gio.IOStream.IOStream), MonadIO m) => O.MethodInfo ClientContextStealConnectionMethodInfo ClientContext signature where
    overloadedMethod _ = clientContextStealConnection

#endif

#if ENABLE_OVERLOADING
type family ResolveClientContextMethod (t :: Symbol) (o :: *) :: * where
    ResolveClientContextMethod "stealConnection" o = ClientContextStealConnectionMethodInfo
    ResolveClientContextMethod "getAddress" o = ClientContextGetAddressMethodInfo
    ResolveClientContextMethod "getAuthDomain" o = ClientContextGetAuthDomainMethodInfo
    ResolveClientContextMethod "getAuthUser" o = ClientContextGetAuthUserMethodInfo
    ResolveClientContextMethod "getGsocket" o = ClientContextGetGsocketMethodInfo
    ResolveClientContextMethod "getHost" o = ClientContextGetHostMethodInfo
    ResolveClientContextMethod "getLocalAddress" o = ClientContextGetLocalAddressMethodInfo
    ResolveClientContextMethod "getRemoteAddress" o = ClientContextGetRemoteAddressMethodInfo
    ResolveClientContextMethod "getSocket" o = ClientContextGetSocketMethodInfo
    ResolveClientContextMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveClientContextMethod t ClientContext, O.MethodInfo info ClientContext p) => OL.IsLabel t (ClientContext -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif