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

-- | 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'
  { -- | 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,
    -- | The 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]
  }
  deriving (HttpHeaderConditionConfig -> HttpHeaderConditionConfig -> Bool
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]
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
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.
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:
--
-- '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.
--
-- 'values', 'httpHeaderConditionConfig_values' - The 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.
newHttpHeaderConditionConfig ::
  HttpHeaderConditionConfig
newHttpHeaderConditionConfig :: HttpHeaderConditionConfig
newHttpHeaderConditionConfig =
  HttpHeaderConditionConfig'
    { $sel:httpHeaderName:HttpHeaderConditionConfig' :: Maybe Text
httpHeaderName =
        forall a. Maybe a
Prelude.Nothing,
      $sel:values:HttpHeaderConditionConfig' :: Maybe [Text]
values = forall a. Maybe a
Prelude.Nothing
    }

-- | 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 :: Lens' HttpHeaderConditionConfig (Maybe Text)
httpHeaderConditionConfig_httpHeaderName = 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)

-- | The 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 :: Lens' HttpHeaderConditionConfig (Maybe [Text])
httpHeaderConditionConfig_values = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

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

instance Prelude.Hashable HttpHeaderConditionConfig where
  hashWithSalt :: Int -> HttpHeaderConditionConfig -> Int
hashWithSalt Int
_salt HttpHeaderConditionConfig' {Maybe [Text]
Maybe Text
values :: Maybe [Text]
httpHeaderName :: Maybe Text
$sel:values:HttpHeaderConditionConfig' :: HttpHeaderConditionConfig -> Maybe [Text]
$sel:httpHeaderName:HttpHeaderConditionConfig' :: HttpHeaderConditionConfig -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
httpHeaderName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe [Text]
values

instance Prelude.NFData HttpHeaderConditionConfig where
  rnf :: HttpHeaderConditionConfig -> ()
rnf HttpHeaderConditionConfig' {Maybe [Text]
Maybe Text
values :: Maybe [Text]
httpHeaderName :: Maybe Text
$sel:values:HttpHeaderConditionConfig' :: HttpHeaderConditionConfig -> Maybe [Text]
$sel:httpHeaderName:HttpHeaderConditionConfig' :: HttpHeaderConditionConfig -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
httpHeaderName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe [Text]
values

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