-- | Presign a URL that expires at the specified amount of time in the future.
--
-- /See:/ 'presign'
presignURL :: (MonadIO m, AWSRequest a, AWSPresigner (Sg (Sv a)))
           => Env
           -> a       -- ^ Request to presign.
           -> UTCTime -- ^ Signing time.
           -> Integer -- ^ Expiry time in seconds.
           -> m ByteString
presignURL e x t ex = (toBS . uri) `liftM` presign e x t ex
  where
    uri rq =
           scheme (secure rq)
        <> build  (host rq)
        <> port'  (port rq)
        <> build  (path rq)
        <> build  (queryString rq)

    scheme True = "https://"
    scheme _    = "http://"

    port' = \case
        80  -> ""
        443 -> ""
        n   -> build ':' <> build n
presignURL :: (MonadIO m, AWSRequest a, AWSPresigner (Sg (Sv a)))
           => Env
           -> a       -- ^ Request to presign.
           -> UTCTime -- ^ Signing time.
           -> Integer -- ^ Expiry time in seconds.
           -> m ByteString
presignURL e x t ex = (toBS . uri) `liftM` presign e x t ex
  where
    uri rq =
           scheme (secure rq)
        <> build  (host rq)
        <> port'  (port rq)
        <> build  (path rq)
        <> build  (queryString rq)

    scheme True = "https://"
    scheme _    = "http://"

    port' = \case
        80  -> ""
        443 -> ""
        n   -> build ':' <> build n
presignURL e x t ex = (toBS . uri) `liftM` presign e x t ex
  where
    uri rq =
           scheme (secure rq)
        <> build  (host rq)
        <> port'  (port rq)
        <> build  (path rq)
        <> build  (queryString rq)

    scheme True = "https://"
    scheme _    = "http://"

    port' = \case
        80  -> ""
        443 -> ""
        n   -> build ':' <> build n