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

import qualified Amazonka.Core as Core
import Amazonka.ELBV2.Types.RedirectActionStatusCodeEnum
import qualified Amazonka.Lens as Lens
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 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 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 hostname. This component is not percent-encoded. The hostname can
    -- contain #{host}.
    RedirectActionConfig -> Maybe Text
host :: 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 HTTP redirect code. The redirect is either permanent (HTTP 301) or
    -- temporary (HTTP 302).
    RedirectActionConfig -> RedirectActionStatusCodeEnum
statusCode :: RedirectActionStatusCodeEnum
  }
  deriving (RedirectActionConfig -> RedirectActionConfig -> Bool
(RedirectActionConfig -> RedirectActionConfig -> Bool)
-> (RedirectActionConfig -> RedirectActionConfig -> Bool)
-> Eq RedirectActionConfig
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]
(Int -> ReadS RedirectActionConfig)
-> ReadS [RedirectActionConfig]
-> ReadPrec RedirectActionConfig
-> ReadPrec [RedirectActionConfig]
-> Read 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
(Int -> RedirectActionConfig -> ShowS)
-> (RedirectActionConfig -> String)
-> ([RedirectActionConfig] -> ShowS)
-> Show RedirectActionConfig
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. RedirectActionConfig -> Rep RedirectActionConfig x)
-> (forall x. Rep RedirectActionConfig x -> RedirectActionConfig)
-> Generic RedirectActionConfig
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:
--
-- 'path', 'redirectActionConfig_path' - The absolute path, starting with the leading \"\/\". This component is
-- not percent-encoded. The path can contain #{host}, #{path}, and #{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.
--
-- 'host', 'redirectActionConfig_host' - The hostname. This component is not percent-encoded. The hostname can
-- contain #{host}.
--
-- 'port', 'redirectActionConfig_port' - The port. You can specify a value from 1 to 65535 or #{port}.
--
-- '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' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> RedirectActionStatusCodeEnum
-> RedirectActionConfig
RedirectActionConfig'
    { $sel:path:RedirectActionConfig' :: Maybe Text
path = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:protocol:RedirectActionConfig' :: Maybe Text
protocol = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:query:RedirectActionConfig' :: Maybe Text
query = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:host:RedirectActionConfig' :: Maybe Text
host = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:port:RedirectActionConfig' :: Maybe Text
port = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:RedirectActionConfig' :: RedirectActionStatusCodeEnum
statusCode = RedirectActionStatusCodeEnum
pStatusCode_
    }

-- | 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 :: (Maybe Text -> f (Maybe Text))
-> RedirectActionConfig -> f RedirectActionConfig
redirectActionConfig_path = (RedirectActionConfig -> Maybe Text)
-> (RedirectActionConfig -> Maybe Text -> RedirectActionConfig)
-> Lens
     RedirectActionConfig RedirectActionConfig (Maybe Text) (Maybe Text)
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 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 :: (Maybe Text -> f (Maybe Text))
-> RedirectActionConfig -> f RedirectActionConfig
redirectActionConfig_protocol = (RedirectActionConfig -> Maybe Text)
-> (RedirectActionConfig -> Maybe Text -> RedirectActionConfig)
-> Lens
     RedirectActionConfig RedirectActionConfig (Maybe Text) (Maybe Text)
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 :: (Maybe Text -> f (Maybe Text))
-> RedirectActionConfig -> f RedirectActionConfig
redirectActionConfig_query = (RedirectActionConfig -> Maybe Text)
-> (RedirectActionConfig -> Maybe Text -> RedirectActionConfig)
-> Lens
     RedirectActionConfig RedirectActionConfig (Maybe Text) (Maybe Text)
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 hostname. This component is not percent-encoded. The hostname can
-- contain #{host}.
redirectActionConfig_host :: Lens.Lens' RedirectActionConfig (Prelude.Maybe Prelude.Text)
redirectActionConfig_host :: (Maybe Text -> f (Maybe Text))
-> RedirectActionConfig -> f RedirectActionConfig
redirectActionConfig_host = (RedirectActionConfig -> Maybe Text)
-> (RedirectActionConfig -> Maybe Text -> RedirectActionConfig)
-> Lens
     RedirectActionConfig RedirectActionConfig (Maybe Text) (Maybe Text)
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 port. You can specify a value from 1 to 65535 or #{port}.
redirectActionConfig_port :: Lens.Lens' RedirectActionConfig (Prelude.Maybe Prelude.Text)
redirectActionConfig_port :: (Maybe Text -> f (Maybe Text))
-> RedirectActionConfig -> f RedirectActionConfig
redirectActionConfig_port = (RedirectActionConfig -> Maybe Text)
-> (RedirectActionConfig -> Maybe Text -> RedirectActionConfig)
-> Lens
     RedirectActionConfig RedirectActionConfig (Maybe Text) (Maybe Text)
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 HTTP redirect code. The redirect is either permanent (HTTP 301) or
-- temporary (HTTP 302).
redirectActionConfig_statusCode :: Lens.Lens' RedirectActionConfig RedirectActionStatusCodeEnum
redirectActionConfig_statusCode :: (RedirectActionStatusCodeEnum -> f RedirectActionStatusCodeEnum)
-> RedirectActionConfig -> f RedirectActionConfig
redirectActionConfig_statusCode = (RedirectActionConfig -> RedirectActionStatusCodeEnum)
-> (RedirectActionConfig
    -> RedirectActionStatusCodeEnum -> RedirectActionConfig)
-> Lens
     RedirectActionConfig
     RedirectActionConfig
     RedirectActionStatusCodeEnum
     RedirectActionStatusCodeEnum
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 Core.FromXML RedirectActionConfig where
  parseXML :: [Node] -> Either String RedirectActionConfig
parseXML [Node]
x =
    Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> RedirectActionStatusCodeEnum
-> RedirectActionConfig
RedirectActionConfig'
      (Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> RedirectActionStatusCodeEnum
 -> RedirectActionConfig)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> RedirectActionStatusCodeEnum
      -> RedirectActionConfig)
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
"Path")
      Either
  String
  (Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> RedirectActionStatusCodeEnum
   -> RedirectActionConfig)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> RedirectActionStatusCodeEnum
      -> RedirectActionConfig)
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
"Protocol")
      Either
  String
  (Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> RedirectActionStatusCodeEnum
   -> RedirectActionConfig)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe Text
      -> RedirectActionStatusCodeEnum
      -> RedirectActionConfig)
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
"Query")
      Either
  String
  (Maybe Text
   -> Maybe Text
   -> RedirectActionStatusCodeEnum
   -> RedirectActionConfig)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> RedirectActionStatusCodeEnum -> RedirectActionConfig)
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
"Host")
      Either
  String
  (Maybe Text
   -> RedirectActionStatusCodeEnum -> RedirectActionConfig)
-> Either String (Maybe Text)
-> Either
     String (RedirectActionStatusCodeEnum -> RedirectActionConfig)
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
"Port")
      Either
  String (RedirectActionStatusCodeEnum -> RedirectActionConfig)
-> Either String RedirectActionStatusCodeEnum
-> Either String RedirectActionConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String RedirectActionStatusCodeEnum
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"StatusCode")

instance Prelude.Hashable RedirectActionConfig

instance Prelude.NFData RedirectActionConfig

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