{-# 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.HttpHeaderConditionConfig
-- 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.HttpHeaderConditionConfig where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about an HTTP header condition.
--
-- There is a set of standard HTTP header fields. You can also define
-- custom HTTP header fields.
--
-- /See:/ 'newHttpHeaderConditionConfig' smart constructor.
data HttpHeaderConditionConfig = HttpHeaderConditionConfig'
  { -- | One or more strings to compare against the value of the HTTP header. The
    -- maximum size of each string is 128 characters. The comparison strings
    -- are case insensitive. The following wildcard characters are supported: *
    -- (matches 0 or more characters) and ? (matches exactly 1 character).
    --
    -- If the same header appears multiple times in the request, we search them
    -- in order until a match is found.
    --
    -- If you specify multiple strings, the condition is satisfied if one of
    -- the strings matches the value of the HTTP header. To require that all of
    -- the strings are a match, create one condition per string.
    HttpHeaderConditionConfig -> Maybe [Text]
values :: Prelude.Maybe [Prelude.Text],
    -- | The name of the HTTP header field. The maximum size is 40 characters.
    -- The header name is case insensitive. The allowed characters are
    -- specified by RFC 7230. Wildcards are not supported.
    --
    -- You can\'t use an HTTP header condition to specify the host header. Use
    -- HostHeaderConditionConfig to specify a host header condition.
    HttpHeaderConditionConfig -> Maybe Text
httpHeaderName :: Prelude.Maybe Prelude.Text
  }
  deriving (HttpHeaderConditionConfig -> HttpHeaderConditionConfig -> Bool
(HttpHeaderConditionConfig -> HttpHeaderConditionConfig -> Bool)
-> (HttpHeaderConditionConfig -> HttpHeaderConditionConfig -> Bool)
-> Eq HttpHeaderConditionConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HttpHeaderConditionConfig -> HttpHeaderConditionConfig -> Bool
$c/= :: HttpHeaderConditionConfig -> HttpHeaderConditionConfig -> Bool
== :: HttpHeaderConditionConfig -> HttpHeaderConditionConfig -> Bool
$c== :: HttpHeaderConditionConfig -> HttpHeaderConditionConfig -> Bool
Prelude.Eq, ReadPrec [HttpHeaderConditionConfig]
ReadPrec HttpHeaderConditionConfig
Int -> ReadS HttpHeaderConditionConfig
ReadS [HttpHeaderConditionConfig]
(Int -> ReadS HttpHeaderConditionConfig)
-> ReadS [HttpHeaderConditionConfig]
-> ReadPrec HttpHeaderConditionConfig
-> ReadPrec [HttpHeaderConditionConfig]
-> Read HttpHeaderConditionConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HttpHeaderConditionConfig]
$creadListPrec :: ReadPrec [HttpHeaderConditionConfig]
readPrec :: ReadPrec HttpHeaderConditionConfig
$creadPrec :: ReadPrec HttpHeaderConditionConfig
readList :: ReadS [HttpHeaderConditionConfig]
$creadList :: ReadS [HttpHeaderConditionConfig]
readsPrec :: Int -> ReadS HttpHeaderConditionConfig
$creadsPrec :: Int -> ReadS HttpHeaderConditionConfig
Prelude.Read, Int -> HttpHeaderConditionConfig -> ShowS
[HttpHeaderConditionConfig] -> ShowS
HttpHeaderConditionConfig -> String
(Int -> HttpHeaderConditionConfig -> ShowS)
-> (HttpHeaderConditionConfig -> String)
-> ([HttpHeaderConditionConfig] -> ShowS)
-> Show HttpHeaderConditionConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HttpHeaderConditionConfig] -> ShowS
$cshowList :: [HttpHeaderConditionConfig] -> ShowS
show :: HttpHeaderConditionConfig -> String
$cshow :: HttpHeaderConditionConfig -> String
showsPrec :: Int -> HttpHeaderConditionConfig -> ShowS
$cshowsPrec :: Int -> HttpHeaderConditionConfig -> ShowS
Prelude.Show, (forall x.
 HttpHeaderConditionConfig -> Rep HttpHeaderConditionConfig x)
-> (forall x.
    Rep HttpHeaderConditionConfig x -> HttpHeaderConditionConfig)
-> Generic HttpHeaderConditionConfig
forall x.
Rep HttpHeaderConditionConfig x -> HttpHeaderConditionConfig
forall x.
HttpHeaderConditionConfig -> Rep HttpHeaderConditionConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep HttpHeaderConditionConfig x -> HttpHeaderConditionConfig
$cfrom :: forall x.
HttpHeaderConditionConfig -> Rep HttpHeaderConditionConfig x
Prelude.Generic)

-- |
-- Create a value of 'HttpHeaderConditionConfig' 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:
--
-- 'values', 'httpHeaderConditionConfig_values' - One or more strings to compare against the value of the HTTP header. The
-- maximum size of each string is 128 characters. The comparison strings
-- are case insensitive. The following wildcard characters are supported: *
-- (matches 0 or more characters) and ? (matches exactly 1 character).
--
-- If the same header appears multiple times in the request, we search them
-- in order until a match is found.
--
-- If you specify multiple strings, the condition is satisfied if one of
-- the strings matches the value of the HTTP header. To require that all of
-- the strings are a match, create one condition per string.
--
-- 'httpHeaderName', 'httpHeaderConditionConfig_httpHeaderName' - The name of the HTTP header field. The maximum size is 40 characters.
-- The header name is case insensitive. The allowed characters are
-- specified by RFC 7230. Wildcards are not supported.
--
-- You can\'t use an HTTP header condition to specify the host header. Use
-- HostHeaderConditionConfig to specify a host header condition.
newHttpHeaderConditionConfig ::
  HttpHeaderConditionConfig
newHttpHeaderConditionConfig :: HttpHeaderConditionConfig
newHttpHeaderConditionConfig =
  HttpHeaderConditionConfig' :: Maybe [Text] -> Maybe Text -> HttpHeaderConditionConfig
HttpHeaderConditionConfig'
    { $sel:values:HttpHeaderConditionConfig' :: Maybe [Text]
values =
        Maybe [Text]
forall a. Maybe a
Prelude.Nothing,
      $sel:httpHeaderName:HttpHeaderConditionConfig' :: Maybe Text
httpHeaderName = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | One or more strings to compare against the value of the HTTP header. The
-- maximum size of each string is 128 characters. The comparison strings
-- are case insensitive. The following wildcard characters are supported: *
-- (matches 0 or more characters) and ? (matches exactly 1 character).
--
-- If the same header appears multiple times in the request, we search them
-- in order until a match is found.
--
-- If you specify multiple strings, the condition is satisfied if one of
-- the strings matches the value of the HTTP header. To require that all of
-- the strings are a match, create one condition per string.
httpHeaderConditionConfig_values :: Lens.Lens' HttpHeaderConditionConfig (Prelude.Maybe [Prelude.Text])
httpHeaderConditionConfig_values :: (Maybe [Text] -> f (Maybe [Text]))
-> HttpHeaderConditionConfig -> f HttpHeaderConditionConfig
httpHeaderConditionConfig_values = (HttpHeaderConditionConfig -> Maybe [Text])
-> (HttpHeaderConditionConfig
    -> Maybe [Text] -> HttpHeaderConditionConfig)
-> Lens
     HttpHeaderConditionConfig
     HttpHeaderConditionConfig
     (Maybe [Text])
     (Maybe [Text])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpHeaderConditionConfig' {Maybe [Text]
values :: Maybe [Text]
$sel:values:HttpHeaderConditionConfig' :: HttpHeaderConditionConfig -> Maybe [Text]
values} -> Maybe [Text]
values) (\s :: HttpHeaderConditionConfig
s@HttpHeaderConditionConfig' {} Maybe [Text]
a -> HttpHeaderConditionConfig
s {$sel:values:HttpHeaderConditionConfig' :: Maybe [Text]
values = Maybe [Text]
a} :: HttpHeaderConditionConfig) ((Maybe [Text] -> f (Maybe [Text]))
 -> HttpHeaderConditionConfig -> f HttpHeaderConditionConfig)
-> ((Maybe [Text] -> f (Maybe [Text]))
    -> Maybe [Text] -> f (Maybe [Text]))
-> (Maybe [Text] -> f (Maybe [Text]))
-> HttpHeaderConditionConfig
-> f HttpHeaderConditionConfig
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [Text] [Text] [Text] [Text]
-> Iso (Maybe [Text]) (Maybe [Text]) (Maybe [Text]) (Maybe [Text])
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso [Text] [Text] [Text] [Text]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name of the HTTP header field. The maximum size is 40 characters.
-- The header name is case insensitive. The allowed characters are
-- specified by RFC 7230. Wildcards are not supported.
--
-- You can\'t use an HTTP header condition to specify the host header. Use
-- HostHeaderConditionConfig to specify a host header condition.
httpHeaderConditionConfig_httpHeaderName :: Lens.Lens' HttpHeaderConditionConfig (Prelude.Maybe Prelude.Text)
httpHeaderConditionConfig_httpHeaderName :: (Maybe Text -> f (Maybe Text))
-> HttpHeaderConditionConfig -> f HttpHeaderConditionConfig
httpHeaderConditionConfig_httpHeaderName = (HttpHeaderConditionConfig -> Maybe Text)
-> (HttpHeaderConditionConfig
    -> Maybe Text -> HttpHeaderConditionConfig)
-> Lens
     HttpHeaderConditionConfig
     HttpHeaderConditionConfig
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HttpHeaderConditionConfig' {Maybe Text
httpHeaderName :: Maybe Text
$sel:httpHeaderName:HttpHeaderConditionConfig' :: HttpHeaderConditionConfig -> Maybe Text
httpHeaderName} -> Maybe Text
httpHeaderName) (\s :: HttpHeaderConditionConfig
s@HttpHeaderConditionConfig' {} Maybe Text
a -> HttpHeaderConditionConfig
s {$sel:httpHeaderName:HttpHeaderConditionConfig' :: Maybe Text
httpHeaderName = Maybe Text
a} :: HttpHeaderConditionConfig)

instance Core.FromXML HttpHeaderConditionConfig where
  parseXML :: [Node] -> Either String HttpHeaderConditionConfig
parseXML [Node]
x =
    Maybe [Text] -> Maybe Text -> HttpHeaderConditionConfig
HttpHeaderConditionConfig'
      (Maybe [Text] -> Maybe Text -> HttpHeaderConditionConfig)
-> Either String (Maybe [Text])
-> Either String (Maybe Text -> HttpHeaderConditionConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( [Node]
x [Node] -> Text -> Either String (Maybe [Node])
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Values" Either String (Maybe [Node]) -> [Node] -> Either String [Node]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Node]
forall a. Monoid a => a
Prelude.mempty
                      Either String [Node]
-> ([Node] -> Either String (Maybe [Text]))
-> Either String (Maybe [Text])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
Prelude.>>= ([Node] -> Either String [Text])
-> [Node] -> Either String (Maybe [Text])
forall (f :: * -> *) a b.
Applicative f =>
([a] -> f b) -> [a] -> f (Maybe b)
Core.may (Text -> [Node] -> Either String [Text]
forall a. FromXML a => Text -> [Node] -> Either String [a]
Core.parseXMLList Text
"member")
                  )
      Either String (Maybe Text -> HttpHeaderConditionConfig)
-> Either String (Maybe Text)
-> Either String HttpHeaderConditionConfig
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
"HttpHeaderName")

instance Prelude.Hashable HttpHeaderConditionConfig

instance Prelude.NFData HttpHeaderConditionConfig

instance Core.ToQuery HttpHeaderConditionConfig where
  toQuery :: HttpHeaderConditionConfig -> QueryString
toQuery HttpHeaderConditionConfig' {Maybe [Text]
Maybe Text
httpHeaderName :: Maybe Text
values :: Maybe [Text]
$sel:httpHeaderName:HttpHeaderConditionConfig' :: HttpHeaderConditionConfig -> Maybe Text
$sel:values:HttpHeaderConditionConfig' :: HttpHeaderConditionConfig -> Maybe [Text]
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"Values"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            (ByteString -> [Text] -> QueryString
forall a.
(IsList a, ToQuery (Item a)) =>
ByteString -> a -> QueryString
Core.toQueryList ByteString
"member" ([Text] -> QueryString) -> Maybe [Text] -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [Text]
values),
        ByteString
"HttpHeaderName" ByteString -> Maybe Text -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Text
httpHeaderName
      ]