{-# 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-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.S3.Types.Redirect where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
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,
    -- | 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 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,
    -- | 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,
    -- | 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
  }
  deriving (Redirect -> Redirect -> Bool
(Redirect -> Redirect -> Bool)
-> (Redirect -> Redirect -> Bool) -> Eq Redirect
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]
(Int -> ReadS Redirect)
-> ReadS [Redirect]
-> ReadPrec Redirect
-> ReadPrec [Redirect]
-> Read 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
(Int -> Redirect -> ShowS)
-> (Redirect -> String) -> ([Redirect] -> ShowS) -> Show Redirect
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. Redirect -> Rep Redirect x)
-> (forall x. Rep Redirect x -> Redirect) -> Generic Redirect
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.
--
-- 'protocol', 'redirect_protocol' - Protocol to use when redirecting requests. The default is the protocol
-- that is used in the original request.
--
-- 'httpRedirectCode', 'redirect_httpRedirectCode' - The HTTP redirect code to use on the response. Not required if one of
-- the siblings is present.
--
-- '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>.
--
-- '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>.
newRedirect ::
  Redirect
newRedirect :: Redirect
newRedirect =
  Redirect' :: Maybe Text
-> Maybe Protocol
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Redirect
Redirect'
    { $sel:hostName:Redirect' :: Maybe Text
hostName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:protocol:Redirect' :: Maybe Protocol
protocol = Maybe Protocol
forall a. Maybe a
Prelude.Nothing,
      $sel:httpRedirectCode:Redirect' :: Maybe Text
httpRedirectCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:replaceKeyWith:Redirect' :: Maybe Text
replaceKeyWith = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:replaceKeyPrefixWith:Redirect' :: Maybe Text
replaceKeyPrefixWith = Maybe Text
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 :: (Maybe Text -> f (Maybe Text)) -> Redirect -> f Redirect
redirect_hostName = (Redirect -> Maybe Text)
-> (Redirect -> Maybe Text -> Redirect)
-> Lens Redirect Redirect (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe Protocol -> f (Maybe Protocol)) -> Redirect -> f Redirect
redirect_protocol = (Redirect -> Maybe Protocol)
-> (Redirect -> Maybe Protocol -> Redirect)
-> Lens Redirect Redirect (Maybe Protocol) (Maybe 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 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 :: (Maybe Text -> f (Maybe Text)) -> Redirect -> f Redirect
redirect_httpRedirectCode = (Redirect -> Maybe Text)
-> (Redirect -> Maybe Text -> Redirect)
-> Lens Redirect Redirect (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> Redirect -> f Redirect
redirect_replaceKeyWith = (Redirect -> Maybe Text)
-> (Redirect -> Maybe Text -> Redirect)
-> Lens Redirect Redirect (Maybe Text) (Maybe Text)
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)

-- | 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 :: (Maybe Text -> f (Maybe Text)) -> Redirect -> f Redirect
redirect_replaceKeyPrefixWith = (Redirect -> Maybe Text)
-> (Redirect -> Maybe Text -> Redirect)
-> Lens Redirect Redirect (Maybe Text) (Maybe Text)
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)

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

instance Prelude.Hashable Redirect

instance Prelude.NFData Redirect

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