{-# 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.CloudFront.Types.CachePolicyHeadersConfig
-- 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.CloudFront.Types.CachePolicyHeadersConfig where

import Amazonka.CloudFront.Types.CachePolicyHeaderBehavior
import Amazonka.CloudFront.Types.Headers
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An object that determines whether any HTTP headers (and if so, which
-- headers) are included in the cache key and automatically included in
-- requests that CloudFront sends to the origin.
--
-- /See:/ 'newCachePolicyHeadersConfig' smart constructor.
data CachePolicyHeadersConfig = CachePolicyHeadersConfig'
  { CachePolicyHeadersConfig -> Maybe Headers
headers :: Prelude.Maybe Headers,
    -- | Determines whether any HTTP headers are included in the cache key and
    -- automatically included in requests that CloudFront sends to the origin.
    -- Valid values are:
    --
    -- -   @none@ – HTTP headers are not included in the cache key and are not
    --     automatically included in requests that CloudFront sends to the
    --     origin. Even when this field is set to @none@, any headers that are
    --     listed in an @OriginRequestPolicy@ /are/ included in origin
    --     requests.
    --
    -- -   @whitelist@ – The HTTP headers that are listed in the @Headers@ type
    --     are included in the cache key and are automatically included in
    --     requests that CloudFront sends to the origin.
    CachePolicyHeadersConfig -> CachePolicyHeaderBehavior
headerBehavior :: CachePolicyHeaderBehavior
  }
  deriving (CachePolicyHeadersConfig -> CachePolicyHeadersConfig -> Bool
(CachePolicyHeadersConfig -> CachePolicyHeadersConfig -> Bool)
-> (CachePolicyHeadersConfig -> CachePolicyHeadersConfig -> Bool)
-> Eq CachePolicyHeadersConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CachePolicyHeadersConfig -> CachePolicyHeadersConfig -> Bool
$c/= :: CachePolicyHeadersConfig -> CachePolicyHeadersConfig -> Bool
== :: CachePolicyHeadersConfig -> CachePolicyHeadersConfig -> Bool
$c== :: CachePolicyHeadersConfig -> CachePolicyHeadersConfig -> Bool
Prelude.Eq, ReadPrec [CachePolicyHeadersConfig]
ReadPrec CachePolicyHeadersConfig
Int -> ReadS CachePolicyHeadersConfig
ReadS [CachePolicyHeadersConfig]
(Int -> ReadS CachePolicyHeadersConfig)
-> ReadS [CachePolicyHeadersConfig]
-> ReadPrec CachePolicyHeadersConfig
-> ReadPrec [CachePolicyHeadersConfig]
-> Read CachePolicyHeadersConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CachePolicyHeadersConfig]
$creadListPrec :: ReadPrec [CachePolicyHeadersConfig]
readPrec :: ReadPrec CachePolicyHeadersConfig
$creadPrec :: ReadPrec CachePolicyHeadersConfig
readList :: ReadS [CachePolicyHeadersConfig]
$creadList :: ReadS [CachePolicyHeadersConfig]
readsPrec :: Int -> ReadS CachePolicyHeadersConfig
$creadsPrec :: Int -> ReadS CachePolicyHeadersConfig
Prelude.Read, Int -> CachePolicyHeadersConfig -> ShowS
[CachePolicyHeadersConfig] -> ShowS
CachePolicyHeadersConfig -> String
(Int -> CachePolicyHeadersConfig -> ShowS)
-> (CachePolicyHeadersConfig -> String)
-> ([CachePolicyHeadersConfig] -> ShowS)
-> Show CachePolicyHeadersConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CachePolicyHeadersConfig] -> ShowS
$cshowList :: [CachePolicyHeadersConfig] -> ShowS
show :: CachePolicyHeadersConfig -> String
$cshow :: CachePolicyHeadersConfig -> String
showsPrec :: Int -> CachePolicyHeadersConfig -> ShowS
$cshowsPrec :: Int -> CachePolicyHeadersConfig -> ShowS
Prelude.Show, (forall x.
 CachePolicyHeadersConfig -> Rep CachePolicyHeadersConfig x)
-> (forall x.
    Rep CachePolicyHeadersConfig x -> CachePolicyHeadersConfig)
-> Generic CachePolicyHeadersConfig
forall x.
Rep CachePolicyHeadersConfig x -> CachePolicyHeadersConfig
forall x.
CachePolicyHeadersConfig -> Rep CachePolicyHeadersConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep CachePolicyHeadersConfig x -> CachePolicyHeadersConfig
$cfrom :: forall x.
CachePolicyHeadersConfig -> Rep CachePolicyHeadersConfig x
Prelude.Generic)

-- |
-- Create a value of 'CachePolicyHeadersConfig' 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:
--
-- 'headers', 'cachePolicyHeadersConfig_headers' - Undocumented member.
--
-- 'headerBehavior', 'cachePolicyHeadersConfig_headerBehavior' - Determines whether any HTTP headers are included in the cache key and
-- automatically included in requests that CloudFront sends to the origin.
-- Valid values are:
--
-- -   @none@ – HTTP headers are not included in the cache key and are not
--     automatically included in requests that CloudFront sends to the
--     origin. Even when this field is set to @none@, any headers that are
--     listed in an @OriginRequestPolicy@ /are/ included in origin
--     requests.
--
-- -   @whitelist@ – The HTTP headers that are listed in the @Headers@ type
--     are included in the cache key and are automatically included in
--     requests that CloudFront sends to the origin.
newCachePolicyHeadersConfig ::
  -- | 'headerBehavior'
  CachePolicyHeaderBehavior ->
  CachePolicyHeadersConfig
newCachePolicyHeadersConfig :: CachePolicyHeaderBehavior -> CachePolicyHeadersConfig
newCachePolicyHeadersConfig CachePolicyHeaderBehavior
pHeaderBehavior_ =
  CachePolicyHeadersConfig' :: Maybe Headers
-> CachePolicyHeaderBehavior -> CachePolicyHeadersConfig
CachePolicyHeadersConfig'
    { $sel:headers:CachePolicyHeadersConfig' :: Maybe Headers
headers =
        Maybe Headers
forall a. Maybe a
Prelude.Nothing,
      $sel:headerBehavior:CachePolicyHeadersConfig' :: CachePolicyHeaderBehavior
headerBehavior = CachePolicyHeaderBehavior
pHeaderBehavior_
    }

-- | Undocumented member.
cachePolicyHeadersConfig_headers :: Lens.Lens' CachePolicyHeadersConfig (Prelude.Maybe Headers)
cachePolicyHeadersConfig_headers :: (Maybe Headers -> f (Maybe Headers))
-> CachePolicyHeadersConfig -> f CachePolicyHeadersConfig
cachePolicyHeadersConfig_headers = (CachePolicyHeadersConfig -> Maybe Headers)
-> (CachePolicyHeadersConfig
    -> Maybe Headers -> CachePolicyHeadersConfig)
-> Lens
     CachePolicyHeadersConfig
     CachePolicyHeadersConfig
     (Maybe Headers)
     (Maybe Headers)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachePolicyHeadersConfig' {Maybe Headers
headers :: Maybe Headers
$sel:headers:CachePolicyHeadersConfig' :: CachePolicyHeadersConfig -> Maybe Headers
headers} -> Maybe Headers
headers) (\s :: CachePolicyHeadersConfig
s@CachePolicyHeadersConfig' {} Maybe Headers
a -> CachePolicyHeadersConfig
s {$sel:headers:CachePolicyHeadersConfig' :: Maybe Headers
headers = Maybe Headers
a} :: CachePolicyHeadersConfig)

-- | Determines whether any HTTP headers are included in the cache key and
-- automatically included in requests that CloudFront sends to the origin.
-- Valid values are:
--
-- -   @none@ – HTTP headers are not included in the cache key and are not
--     automatically included in requests that CloudFront sends to the
--     origin. Even when this field is set to @none@, any headers that are
--     listed in an @OriginRequestPolicy@ /are/ included in origin
--     requests.
--
-- -   @whitelist@ – The HTTP headers that are listed in the @Headers@ type
--     are included in the cache key and are automatically included in
--     requests that CloudFront sends to the origin.
cachePolicyHeadersConfig_headerBehavior :: Lens.Lens' CachePolicyHeadersConfig CachePolicyHeaderBehavior
cachePolicyHeadersConfig_headerBehavior :: (CachePolicyHeaderBehavior -> f CachePolicyHeaderBehavior)
-> CachePolicyHeadersConfig -> f CachePolicyHeadersConfig
cachePolicyHeadersConfig_headerBehavior = (CachePolicyHeadersConfig -> CachePolicyHeaderBehavior)
-> (CachePolicyHeadersConfig
    -> CachePolicyHeaderBehavior -> CachePolicyHeadersConfig)
-> Lens
     CachePolicyHeadersConfig
     CachePolicyHeadersConfig
     CachePolicyHeaderBehavior
     CachePolicyHeaderBehavior
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CachePolicyHeadersConfig' {CachePolicyHeaderBehavior
headerBehavior :: CachePolicyHeaderBehavior
$sel:headerBehavior:CachePolicyHeadersConfig' :: CachePolicyHeadersConfig -> CachePolicyHeaderBehavior
headerBehavior} -> CachePolicyHeaderBehavior
headerBehavior) (\s :: CachePolicyHeadersConfig
s@CachePolicyHeadersConfig' {} CachePolicyHeaderBehavior
a -> CachePolicyHeadersConfig
s {$sel:headerBehavior:CachePolicyHeadersConfig' :: CachePolicyHeaderBehavior
headerBehavior = CachePolicyHeaderBehavior
a} :: CachePolicyHeadersConfig)

instance Core.FromXML CachePolicyHeadersConfig where
  parseXML :: [Node] -> Either String CachePolicyHeadersConfig
parseXML [Node]
x =
    Maybe Headers
-> CachePolicyHeaderBehavior -> CachePolicyHeadersConfig
CachePolicyHeadersConfig'
      (Maybe Headers
 -> CachePolicyHeaderBehavior -> CachePolicyHeadersConfig)
-> Either String (Maybe Headers)
-> Either
     String (CachePolicyHeaderBehavior -> CachePolicyHeadersConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ([Node]
x [Node] -> Text -> Either String (Maybe Headers)
forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
Core..@? Text
"Headers")
      Either
  String (CachePolicyHeaderBehavior -> CachePolicyHeadersConfig)
-> Either String CachePolicyHeaderBehavior
-> Either String CachePolicyHeadersConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String CachePolicyHeaderBehavior
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"HeaderBehavior")

instance Prelude.Hashable CachePolicyHeadersConfig

instance Prelude.NFData CachePolicyHeadersConfig

instance Core.ToXML CachePolicyHeadersConfig where
  toXML :: CachePolicyHeadersConfig -> XML
toXML CachePolicyHeadersConfig' {Maybe Headers
CachePolicyHeaderBehavior
headerBehavior :: CachePolicyHeaderBehavior
headers :: Maybe Headers
$sel:headerBehavior:CachePolicyHeadersConfig' :: CachePolicyHeadersConfig -> CachePolicyHeaderBehavior
$sel:headers:CachePolicyHeadersConfig' :: CachePolicyHeadersConfig -> Maybe Headers
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Headers" Name -> Maybe Headers -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Headers
headers,
        Name
"HeaderBehavior" Name -> CachePolicyHeaderBehavior -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= CachePolicyHeaderBehavior
headerBehavior
      ]