{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.S3.Types.Redirect
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.S3.Types.Redirect where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.S3.Internal
import Amazonka.S3.Types.Protocol

-- | Specifies how requests are redirected. In the event of an error, you can
-- specify a different error code to return.
--
-- /See:/ 'newRedirect' smart constructor.
data Redirect = Redirect'
  { -- | The host name to use in the redirect request.
    Redirect -> Maybe Text
hostName :: Prelude.Maybe Prelude.Text,
    -- | The HTTP redirect code to use on the response. Not required if one of
    -- the siblings is present.
    Redirect -> Maybe Text
httpRedirectCode :: Prelude.Maybe Prelude.Text,
    -- | Protocol to use when redirecting requests. The default is the protocol
    -- that is used in the original request.
    Redirect -> Maybe Protocol
protocol :: Prelude.Maybe Protocol,
    -- | The object key prefix to use in the redirect request. For example, to
    -- redirect requests for all pages with prefix @docs\/@ (objects in the
    -- @docs\/@ folder) to @documents\/@, you can set a condition block with
    -- @KeyPrefixEquals@ set to @docs\/@ and in the Redirect set
    -- @ReplaceKeyPrefixWith@ to @\/documents@. Not required if one of the
    -- siblings is present. Can be present only if @ReplaceKeyWith@ is not
    -- provided.
    --
    -- Replacement must be made for object keys containing special characters
    -- (such as carriage returns) when using XML requests. For more
    -- information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
    Redirect -> Maybe Text
replaceKeyPrefixWith :: Prelude.Maybe Prelude.Text,
    -- | The specific object key to use in the redirect request. For example,
    -- redirect request to @error.html@. Not required if one of the siblings is
    -- present. Can be present only if @ReplaceKeyPrefixWith@ is not provided.
    --
    -- Replacement must be made for object keys containing special characters
    -- (such as carriage returns) when using XML requests. For more
    -- information, see
    -- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
    Redirect -> Maybe Text
replaceKeyWith :: Prelude.Maybe Prelude.Text
  }
  deriving (Redirect -> Redirect -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Redirect -> Redirect -> Bool
$c/= :: Redirect -> Redirect -> Bool
== :: Redirect -> Redirect -> Bool
$c== :: Redirect -> Redirect -> Bool
Prelude.Eq, ReadPrec [Redirect]
ReadPrec Redirect
Int -> ReadS Redirect
ReadS [Redirect]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Redirect]
$creadListPrec :: ReadPrec [Redirect]
readPrec :: ReadPrec Redirect
$creadPrec :: ReadPrec Redirect
readList :: ReadS [Redirect]
$creadList :: ReadS [Redirect]
readsPrec :: Int -> ReadS Redirect
$creadsPrec :: Int -> ReadS Redirect
Prelude.Read, Int -> Redirect -> ShowS
[Redirect] -> ShowS
Redirect -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Redirect] -> ShowS
$cshowList :: [Redirect] -> ShowS
show :: Redirect -> String
$cshow :: Redirect -> String
showsPrec :: Int -> Redirect -> ShowS
$cshowsPrec :: Int -> Redirect -> ShowS
Prelude.Show, forall x. Rep Redirect x -> Redirect
forall x. Redirect -> Rep Redirect x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Redirect x -> Redirect
$cfrom :: forall x. Redirect -> Rep Redirect x
Prelude.Generic)

-- |
-- Create a value of 'Redirect' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'hostName', 'redirect_hostName' - The host name to use in the redirect request.
--
-- 'httpRedirectCode', 'redirect_httpRedirectCode' - The HTTP redirect code to use on the response. Not required if one of
-- the siblings is present.
--
-- 'protocol', 'redirect_protocol' - Protocol to use when redirecting requests. The default is the protocol
-- that is used in the original request.
--
-- 'replaceKeyPrefixWith', 'redirect_replaceKeyPrefixWith' - The object key prefix to use in the redirect request. For example, to
-- redirect requests for all pages with prefix @docs\/@ (objects in the
-- @docs\/@ folder) to @documents\/@, you can set a condition block with
-- @KeyPrefixEquals@ set to @docs\/@ and in the Redirect set
-- @ReplaceKeyPrefixWith@ to @\/documents@. Not required if one of the
-- siblings is present. Can be present only if @ReplaceKeyWith@ is not
-- provided.
--
-- Replacement must be made for object keys containing special characters
-- (such as carriage returns) when using XML requests. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
--
-- 'replaceKeyWith', 'redirect_replaceKeyWith' - The specific object key to use in the redirect request. For example,
-- redirect request to @error.html@. Not required if one of the siblings is
-- present. Can be present only if @ReplaceKeyPrefixWith@ is not provided.
--
-- Replacement must be made for object keys containing special characters
-- (such as carriage returns) when using XML requests. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
newRedirect ::
  Redirect
newRedirect :: Redirect
newRedirect =
  Redirect'
    { $sel:hostName:Redirect' :: Maybe Text
hostName = forall a. Maybe a
Prelude.Nothing,
      $sel:httpRedirectCode:Redirect' :: Maybe Text
httpRedirectCode = forall a. Maybe a
Prelude.Nothing,
      $sel:protocol:Redirect' :: Maybe Protocol
protocol = forall a. Maybe a
Prelude.Nothing,
      $sel:replaceKeyPrefixWith:Redirect' :: Maybe Text
replaceKeyPrefixWith = forall a. Maybe a
Prelude.Nothing,
      $sel:replaceKeyWith:Redirect' :: Maybe Text
replaceKeyWith = forall a. Maybe a
Prelude.Nothing
    }

-- | The host name to use in the redirect request.
redirect_hostName :: Lens.Lens' Redirect (Prelude.Maybe Prelude.Text)
redirect_hostName :: Lens' Redirect (Maybe Text)
redirect_hostName = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Redirect' {Maybe Text
hostName :: Maybe Text
$sel:hostName:Redirect' :: Redirect -> Maybe Text
hostName} -> Maybe Text
hostName) (\s :: Redirect
s@Redirect' {} Maybe Text
a -> Redirect
s {$sel:hostName:Redirect' :: Maybe Text
hostName = Maybe Text
a} :: Redirect)

-- | The HTTP redirect code to use on the response. Not required if one of
-- the siblings is present.
redirect_httpRedirectCode :: Lens.Lens' Redirect (Prelude.Maybe Prelude.Text)
redirect_httpRedirectCode :: Lens' Redirect (Maybe Text)
redirect_httpRedirectCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Redirect' {Maybe Text
httpRedirectCode :: Maybe Text
$sel:httpRedirectCode:Redirect' :: Redirect -> Maybe Text
httpRedirectCode} -> Maybe Text
httpRedirectCode) (\s :: Redirect
s@Redirect' {} Maybe Text
a -> Redirect
s {$sel:httpRedirectCode:Redirect' :: Maybe Text
httpRedirectCode = Maybe Text
a} :: Redirect)

-- | Protocol to use when redirecting requests. The default is the protocol
-- that is used in the original request.
redirect_protocol :: Lens.Lens' Redirect (Prelude.Maybe Protocol)
redirect_protocol :: Lens' Redirect (Maybe Protocol)
redirect_protocol = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Redirect' {Maybe Protocol
protocol :: Maybe Protocol
$sel:protocol:Redirect' :: Redirect -> Maybe Protocol
protocol} -> Maybe Protocol
protocol) (\s :: Redirect
s@Redirect' {} Maybe Protocol
a -> Redirect
s {$sel:protocol:Redirect' :: Maybe Protocol
protocol = Maybe Protocol
a} :: Redirect)

-- | The object key prefix to use in the redirect request. For example, to
-- redirect requests for all pages with prefix @docs\/@ (objects in the
-- @docs\/@ folder) to @documents\/@, you can set a condition block with
-- @KeyPrefixEquals@ set to @docs\/@ and in the Redirect set
-- @ReplaceKeyPrefixWith@ to @\/documents@. Not required if one of the
-- siblings is present. Can be present only if @ReplaceKeyWith@ is not
-- provided.
--
-- Replacement must be made for object keys containing special characters
-- (such as carriage returns) when using XML requests. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
redirect_replaceKeyPrefixWith :: Lens.Lens' Redirect (Prelude.Maybe Prelude.Text)
redirect_replaceKeyPrefixWith :: Lens' Redirect (Maybe Text)
redirect_replaceKeyPrefixWith = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Redirect' {Maybe Text
replaceKeyPrefixWith :: Maybe Text
$sel:replaceKeyPrefixWith:Redirect' :: Redirect -> Maybe Text
replaceKeyPrefixWith} -> Maybe Text
replaceKeyPrefixWith) (\s :: Redirect
s@Redirect' {} Maybe Text
a -> Redirect
s {$sel:replaceKeyPrefixWith:Redirect' :: Maybe Text
replaceKeyPrefixWith = Maybe Text
a} :: Redirect)

-- | The specific object key to use in the redirect request. For example,
-- redirect request to @error.html@. Not required if one of the siblings is
-- present. Can be present only if @ReplaceKeyPrefixWith@ is not provided.
--
-- Replacement must be made for object keys containing special characters
-- (such as carriage returns) when using XML requests. For more
-- information, see
-- <https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html#object-key-xml-related-constraints XML related object key constraints>.
redirect_replaceKeyWith :: Lens.Lens' Redirect (Prelude.Maybe Prelude.Text)
redirect_replaceKeyWith :: Lens' Redirect (Maybe Text)
redirect_replaceKeyWith = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Redirect' {Maybe Text
replaceKeyWith :: Maybe Text
$sel:replaceKeyWith:Redirect' :: Redirect -> Maybe Text
replaceKeyWith} -> Maybe Text
replaceKeyWith) (\s :: Redirect
s@Redirect' {} Maybe Text
a -> Redirect
s {$sel:replaceKeyWith:Redirect' :: Maybe Text
replaceKeyWith = Maybe Text
a} :: Redirect)

instance Data.FromXML Redirect where
  parseXML :: [Node] -> Either String Redirect
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> Maybe Protocol
-> Maybe Text
-> Maybe Text
-> Redirect
Redirect'
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"HostName")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"HttpRedirectCode")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"Protocol")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"ReplaceKeyPrefixWith")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Data..@? Text
"ReplaceKeyWith")

instance Prelude.Hashable Redirect where
  hashWithSalt :: Int -> Redirect -> Int
hashWithSalt Int
_salt Redirect' {Maybe Text
Maybe Protocol
replaceKeyWith :: Maybe Text
replaceKeyPrefixWith :: Maybe Text
protocol :: Maybe Protocol
httpRedirectCode :: Maybe Text
hostName :: Maybe Text
$sel:replaceKeyWith:Redirect' :: Redirect -> Maybe Text
$sel:replaceKeyPrefixWith:Redirect' :: Redirect -> Maybe Text
$sel:protocol:Redirect' :: Redirect -> Maybe Protocol
$sel:httpRedirectCode:Redirect' :: Redirect -> Maybe Text
$sel:hostName:Redirect' :: Redirect -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
hostName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
httpRedirectCode
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Protocol
protocol
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
replaceKeyPrefixWith
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
replaceKeyWith

instance Prelude.NFData Redirect where
  rnf :: Redirect -> ()
rnf Redirect' {Maybe Text
Maybe Protocol
replaceKeyWith :: Maybe Text
replaceKeyPrefixWith :: Maybe Text
protocol :: Maybe Protocol
httpRedirectCode :: Maybe Text
hostName :: Maybe Text
$sel:replaceKeyWith:Redirect' :: Redirect -> Maybe Text
$sel:replaceKeyPrefixWith:Redirect' :: Redirect -> Maybe Text
$sel:protocol:Redirect' :: Redirect -> Maybe Protocol
$sel:httpRedirectCode:Redirect' :: Redirect -> Maybe Text
$sel:hostName:Redirect' :: Redirect -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
hostName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
httpRedirectCode
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Protocol
protocol
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
replaceKeyPrefixWith
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
replaceKeyWith

instance Data.ToXML Redirect where
  toXML :: Redirect -> XML
toXML Redirect' {Maybe Text
Maybe Protocol
replaceKeyWith :: Maybe Text
replaceKeyPrefixWith :: Maybe Text
protocol :: Maybe Protocol
httpRedirectCode :: Maybe Text
hostName :: Maybe Text
$sel:replaceKeyWith:Redirect' :: Redirect -> Maybe Text
$sel:replaceKeyPrefixWith:Redirect' :: Redirect -> Maybe Text
$sel:protocol:Redirect' :: Redirect -> Maybe Protocol
$sel:httpRedirectCode:Redirect' :: Redirect -> Maybe Text
$sel:hostName:Redirect' :: Redirect -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"HostName" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Text
hostName,
        Name
"HttpRedirectCode" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Text
httpRedirectCode,
        Name
"Protocol" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Protocol
protocol,
        Name
"ReplaceKeyPrefixWith" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Text
replaceKeyPrefixWith,
        Name
"ReplaceKeyWith" forall a. ToXML a => Name -> a -> XML
Data.@= Maybe Text
replaceKeyWith
      ]