{-# 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.ELBV2.Types.RedirectActionConfig
-- 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.ELBV2.Types.RedirectActionConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.ELBV2.Types.RedirectActionStatusCodeEnum
import qualified Amazonka.Prelude as Prelude

-- | Information about a redirect action.
--
-- A URI consists of the following components:
-- protocol:\/\/hostname:port\/path?query. You must modify at least one of
-- the following components to avoid a redirect loop: protocol, hostname,
-- port, or path. Any components that you do not modify retain their
-- original values.
--
-- You can reuse URI components using the following reserved keywords:
--
-- -   #{protocol}
--
-- -   #{host}
--
-- -   #{port}
--
-- -   #{path} (the leading \"\/\" is removed)
--
-- -   #{query}
--
-- For example, you can change the path to \"\/new\/#{path}\", the hostname
-- to \"example.#{host}\", or the query to \"#{query}&value=xyz\".
--
-- /See:/ 'newRedirectActionConfig' smart constructor.
data RedirectActionConfig = RedirectActionConfig'
  { -- | The hostname. This component is not percent-encoded. The hostname can
    -- contain #{host}.
    RedirectActionConfig -> Maybe Text
host :: Prelude.Maybe Prelude.Text,
    -- | The absolute path, starting with the leading \"\/\". This component is
    -- not percent-encoded. The path can contain #{host}, #{path}, and #{port}.
    RedirectActionConfig -> Maybe Text
path :: Prelude.Maybe Prelude.Text,
    -- | The port. You can specify a value from 1 to 65535 or #{port}.
    RedirectActionConfig -> Maybe Text
port :: Prelude.Maybe Prelude.Text,
    -- | The protocol. You can specify HTTP, HTTPS, or #{protocol}. You can
    -- redirect HTTP to HTTP, HTTP to HTTPS, and HTTPS to HTTPS. You cannot
    -- redirect HTTPS to HTTP.
    RedirectActionConfig -> Maybe Text
protocol :: Prelude.Maybe Prelude.Text,
    -- | The query parameters, URL-encoded when necessary, but not
    -- percent-encoded. Do not include the leading \"?\", as it is
    -- automatically added. You can specify any of the reserved keywords.
    RedirectActionConfig -> Maybe Text
query :: Prelude.Maybe Prelude.Text,
    -- | The HTTP redirect code. The redirect is either permanent (HTTP 301) or
    -- temporary (HTTP 302).
    RedirectActionConfig -> RedirectActionStatusCodeEnum
statusCode :: RedirectActionStatusCodeEnum
  }
  deriving (RedirectActionConfig -> RedirectActionConfig -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RedirectActionConfig -> RedirectActionConfig -> Bool
$c/= :: RedirectActionConfig -> RedirectActionConfig -> Bool
== :: RedirectActionConfig -> RedirectActionConfig -> Bool
$c== :: RedirectActionConfig -> RedirectActionConfig -> Bool
Prelude.Eq, ReadPrec [RedirectActionConfig]
ReadPrec RedirectActionConfig
Int -> ReadS RedirectActionConfig
ReadS [RedirectActionConfig]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RedirectActionConfig]
$creadListPrec :: ReadPrec [RedirectActionConfig]
readPrec :: ReadPrec RedirectActionConfig
$creadPrec :: ReadPrec RedirectActionConfig
readList :: ReadS [RedirectActionConfig]
$creadList :: ReadS [RedirectActionConfig]
readsPrec :: Int -> ReadS RedirectActionConfig
$creadsPrec :: Int -> ReadS RedirectActionConfig
Prelude.Read, Int -> RedirectActionConfig -> ShowS
[RedirectActionConfig] -> ShowS
RedirectActionConfig -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RedirectActionConfig] -> ShowS
$cshowList :: [RedirectActionConfig] -> ShowS
show :: RedirectActionConfig -> String
$cshow :: RedirectActionConfig -> String
showsPrec :: Int -> RedirectActionConfig -> ShowS
$cshowsPrec :: Int -> RedirectActionConfig -> ShowS
Prelude.Show, forall x. Rep RedirectActionConfig x -> RedirectActionConfig
forall x. RedirectActionConfig -> Rep RedirectActionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RedirectActionConfig x -> RedirectActionConfig
$cfrom :: forall x. RedirectActionConfig -> Rep RedirectActionConfig x
Prelude.Generic)

-- |
-- Create a value of 'RedirectActionConfig' 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:
--
-- 'host', 'redirectActionConfig_host' - The hostname. This component is not percent-encoded. The hostname can
-- contain #{host}.
--
-- 'path', 'redirectActionConfig_path' - The absolute path, starting with the leading \"\/\". This component is
-- not percent-encoded. The path can contain #{host}, #{path}, and #{port}.
--
-- 'port', 'redirectActionConfig_port' - The port. You can specify a value from 1 to 65535 or #{port}.
--
-- 'protocol', 'redirectActionConfig_protocol' - The protocol. You can specify HTTP, HTTPS, or #{protocol}. You can
-- redirect HTTP to HTTP, HTTP to HTTPS, and HTTPS to HTTPS. You cannot
-- redirect HTTPS to HTTP.
--
-- 'query', 'redirectActionConfig_query' - The query parameters, URL-encoded when necessary, but not
-- percent-encoded. Do not include the leading \"?\", as it is
-- automatically added. You can specify any of the reserved keywords.
--
-- 'statusCode', 'redirectActionConfig_statusCode' - The HTTP redirect code. The redirect is either permanent (HTTP 301) or
-- temporary (HTTP 302).
newRedirectActionConfig ::
  -- | 'statusCode'
  RedirectActionStatusCodeEnum ->
  RedirectActionConfig
newRedirectActionConfig :: RedirectActionStatusCodeEnum -> RedirectActionConfig
newRedirectActionConfig RedirectActionStatusCodeEnum
pStatusCode_ =
  RedirectActionConfig'
    { $sel:host:RedirectActionConfig' :: Maybe Text
host = forall a. Maybe a
Prelude.Nothing,
      $sel:path:RedirectActionConfig' :: Maybe Text
path = forall a. Maybe a
Prelude.Nothing,
      $sel:port:RedirectActionConfig' :: Maybe Text
port = forall a. Maybe a
Prelude.Nothing,
      $sel:protocol:RedirectActionConfig' :: Maybe Text
protocol = forall a. Maybe a
Prelude.Nothing,
      $sel:query:RedirectActionConfig' :: Maybe Text
query = forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:RedirectActionConfig' :: RedirectActionStatusCodeEnum
statusCode = RedirectActionStatusCodeEnum
pStatusCode_
    }

-- | The hostname. This component is not percent-encoded. The hostname can
-- contain #{host}.
redirectActionConfig_host :: Lens.Lens' RedirectActionConfig (Prelude.Maybe Prelude.Text)
redirectActionConfig_host :: Lens' RedirectActionConfig (Maybe Text)
redirectActionConfig_host = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedirectActionConfig' {Maybe Text
host :: Maybe Text
$sel:host:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
host} -> Maybe Text
host) (\s :: RedirectActionConfig
s@RedirectActionConfig' {} Maybe Text
a -> RedirectActionConfig
s {$sel:host:RedirectActionConfig' :: Maybe Text
host = Maybe Text
a} :: RedirectActionConfig)

-- | The absolute path, starting with the leading \"\/\". This component is
-- not percent-encoded. The path can contain #{host}, #{path}, and #{port}.
redirectActionConfig_path :: Lens.Lens' RedirectActionConfig (Prelude.Maybe Prelude.Text)
redirectActionConfig_path :: Lens' RedirectActionConfig (Maybe Text)
redirectActionConfig_path = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedirectActionConfig' {Maybe Text
path :: Maybe Text
$sel:path:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
path} -> Maybe Text
path) (\s :: RedirectActionConfig
s@RedirectActionConfig' {} Maybe Text
a -> RedirectActionConfig
s {$sel:path:RedirectActionConfig' :: Maybe Text
path = Maybe Text
a} :: RedirectActionConfig)

-- | The port. You can specify a value from 1 to 65535 or #{port}.
redirectActionConfig_port :: Lens.Lens' RedirectActionConfig (Prelude.Maybe Prelude.Text)
redirectActionConfig_port :: Lens' RedirectActionConfig (Maybe Text)
redirectActionConfig_port = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedirectActionConfig' {Maybe Text
port :: Maybe Text
$sel:port:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
port} -> Maybe Text
port) (\s :: RedirectActionConfig
s@RedirectActionConfig' {} Maybe Text
a -> RedirectActionConfig
s {$sel:port:RedirectActionConfig' :: Maybe Text
port = Maybe Text
a} :: RedirectActionConfig)

-- | The protocol. You can specify HTTP, HTTPS, or #{protocol}. You can
-- redirect HTTP to HTTP, HTTP to HTTPS, and HTTPS to HTTPS. You cannot
-- redirect HTTPS to HTTP.
redirectActionConfig_protocol :: Lens.Lens' RedirectActionConfig (Prelude.Maybe Prelude.Text)
redirectActionConfig_protocol :: Lens' RedirectActionConfig (Maybe Text)
redirectActionConfig_protocol = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedirectActionConfig' {Maybe Text
protocol :: Maybe Text
$sel:protocol:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
protocol} -> Maybe Text
protocol) (\s :: RedirectActionConfig
s@RedirectActionConfig' {} Maybe Text
a -> RedirectActionConfig
s {$sel:protocol:RedirectActionConfig' :: Maybe Text
protocol = Maybe Text
a} :: RedirectActionConfig)

-- | The query parameters, URL-encoded when necessary, but not
-- percent-encoded. Do not include the leading \"?\", as it is
-- automatically added. You can specify any of the reserved keywords.
redirectActionConfig_query :: Lens.Lens' RedirectActionConfig (Prelude.Maybe Prelude.Text)
redirectActionConfig_query :: Lens' RedirectActionConfig (Maybe Text)
redirectActionConfig_query = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedirectActionConfig' {Maybe Text
query :: Maybe Text
$sel:query:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
query} -> Maybe Text
query) (\s :: RedirectActionConfig
s@RedirectActionConfig' {} Maybe Text
a -> RedirectActionConfig
s {$sel:query:RedirectActionConfig' :: Maybe Text
query = Maybe Text
a} :: RedirectActionConfig)

-- | The HTTP redirect code. The redirect is either permanent (HTTP 301) or
-- temporary (HTTP 302).
redirectActionConfig_statusCode :: Lens.Lens' RedirectActionConfig RedirectActionStatusCodeEnum
redirectActionConfig_statusCode :: Lens' RedirectActionConfig RedirectActionStatusCodeEnum
redirectActionConfig_statusCode = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RedirectActionConfig' {RedirectActionStatusCodeEnum
statusCode :: RedirectActionStatusCodeEnum
$sel:statusCode:RedirectActionConfig' :: RedirectActionConfig -> RedirectActionStatusCodeEnum
statusCode} -> RedirectActionStatusCodeEnum
statusCode) (\s :: RedirectActionConfig
s@RedirectActionConfig' {} RedirectActionStatusCodeEnum
a -> RedirectActionConfig
s {$sel:statusCode:RedirectActionConfig' :: RedirectActionStatusCodeEnum
statusCode = RedirectActionStatusCodeEnum
a} :: RedirectActionConfig)

instance Data.FromXML RedirectActionConfig where
  parseXML :: [Node] -> Either String RedirectActionConfig
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> RedirectActionStatusCodeEnum
-> RedirectActionConfig
RedirectActionConfig'
      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
"Host")
      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
"Path")
      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
"Port")
      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
"Query")
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
Data..@ Text
"StatusCode")

instance Prelude.Hashable RedirectActionConfig where
  hashWithSalt :: Int -> RedirectActionConfig -> Int
hashWithSalt Int
_salt RedirectActionConfig' {Maybe Text
RedirectActionStatusCodeEnum
statusCode :: RedirectActionStatusCodeEnum
query :: Maybe Text
protocol :: Maybe Text
port :: Maybe Text
path :: Maybe Text
host :: Maybe Text
$sel:statusCode:RedirectActionConfig' :: RedirectActionConfig -> RedirectActionStatusCodeEnum
$sel:query:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:protocol:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:port:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:path:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:host:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
host
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
path
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
port
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
protocol
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
query
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` RedirectActionStatusCodeEnum
statusCode

instance Prelude.NFData RedirectActionConfig where
  rnf :: RedirectActionConfig -> ()
rnf RedirectActionConfig' {Maybe Text
RedirectActionStatusCodeEnum
statusCode :: RedirectActionStatusCodeEnum
query :: Maybe Text
protocol :: Maybe Text
port :: Maybe Text
path :: Maybe Text
host :: Maybe Text
$sel:statusCode:RedirectActionConfig' :: RedirectActionConfig -> RedirectActionStatusCodeEnum
$sel:query:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:protocol:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:port:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:path:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:host:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
host
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
path
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
port
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
protocol
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
query
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf RedirectActionStatusCodeEnum
statusCode

instance Data.ToQuery RedirectActionConfig where
  toQuery :: RedirectActionConfig -> QueryString
toQuery RedirectActionConfig' {Maybe Text
RedirectActionStatusCodeEnum
statusCode :: RedirectActionStatusCodeEnum
query :: Maybe Text
protocol :: Maybe Text
port :: Maybe Text
path :: Maybe Text
host :: Maybe Text
$sel:statusCode:RedirectActionConfig' :: RedirectActionConfig -> RedirectActionStatusCodeEnum
$sel:query:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:protocol:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:port:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:path:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
$sel:host:RedirectActionConfig' :: RedirectActionConfig -> Maybe Text
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Host" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
host,
        ByteString
"Path" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
path,
        ByteString
"Port" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
port,
        ByteString
"Protocol" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
protocol,
        ByteString
"Query" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: Maybe Text
query,
        ByteString
"StatusCode" forall a. ToQuery a => ByteString -> a -> QueryString
Data.=: RedirectActionStatusCodeEnum
statusCode
      ]