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

import Amazonka.CloudFront.Types.Headers
import Amazonka.CloudFront.Types.OriginRequestPolicyHeaderBehavior
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 requests that CloudFront sends to the origin.
--
-- /See:/ 'newOriginRequestPolicyHeadersConfig' smart constructor.
data OriginRequestPolicyHeadersConfig = OriginRequestPolicyHeadersConfig'
  { OriginRequestPolicyHeadersConfig -> Maybe Headers
headers :: Prelude.Maybe Headers,
    -- | Determines whether any HTTP headers are included in requests that
    -- CloudFront sends to the origin. Valid values are:
    --
    -- -   @none@ – HTTP headers are not included in requests that CloudFront
    --     sends to the origin. Even when this field is set to @none@, any
    --     headers that are listed in a @CachePolicy@ /are/ included in origin
    --     requests.
    --
    -- -   @whitelist@ – The HTTP headers that are listed in the @Headers@ type
    --     are included in requests that CloudFront sends to the origin.
    --
    -- -   @allViewer@ – All HTTP headers in viewer requests are included in
    --     requests that CloudFront sends to the origin.
    --
    -- -   @allViewerAndWhitelistCloudFront@ – All HTTP headers in viewer
    --     requests and the additional CloudFront headers that are listed in
    --     the @Headers@ type are included in requests that CloudFront sends to
    --     the origin. The additional headers are added by CloudFront.
    OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyHeaderBehavior
headerBehavior :: OriginRequestPolicyHeaderBehavior
  }
  deriving (OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyHeadersConfig -> Bool
(OriginRequestPolicyHeadersConfig
 -> OriginRequestPolicyHeadersConfig -> Bool)
-> (OriginRequestPolicyHeadersConfig
    -> OriginRequestPolicyHeadersConfig -> Bool)
-> Eq OriginRequestPolicyHeadersConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyHeadersConfig -> Bool
$c/= :: OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyHeadersConfig -> Bool
== :: OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyHeadersConfig -> Bool
$c== :: OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyHeadersConfig -> Bool
Prelude.Eq, ReadPrec [OriginRequestPolicyHeadersConfig]
ReadPrec OriginRequestPolicyHeadersConfig
Int -> ReadS OriginRequestPolicyHeadersConfig
ReadS [OriginRequestPolicyHeadersConfig]
(Int -> ReadS OriginRequestPolicyHeadersConfig)
-> ReadS [OriginRequestPolicyHeadersConfig]
-> ReadPrec OriginRequestPolicyHeadersConfig
-> ReadPrec [OriginRequestPolicyHeadersConfig]
-> Read OriginRequestPolicyHeadersConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OriginRequestPolicyHeadersConfig]
$creadListPrec :: ReadPrec [OriginRequestPolicyHeadersConfig]
readPrec :: ReadPrec OriginRequestPolicyHeadersConfig
$creadPrec :: ReadPrec OriginRequestPolicyHeadersConfig
readList :: ReadS [OriginRequestPolicyHeadersConfig]
$creadList :: ReadS [OriginRequestPolicyHeadersConfig]
readsPrec :: Int -> ReadS OriginRequestPolicyHeadersConfig
$creadsPrec :: Int -> ReadS OriginRequestPolicyHeadersConfig
Prelude.Read, Int -> OriginRequestPolicyHeadersConfig -> ShowS
[OriginRequestPolicyHeadersConfig] -> ShowS
OriginRequestPolicyHeadersConfig -> String
(Int -> OriginRequestPolicyHeadersConfig -> ShowS)
-> (OriginRequestPolicyHeadersConfig -> String)
-> ([OriginRequestPolicyHeadersConfig] -> ShowS)
-> Show OriginRequestPolicyHeadersConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OriginRequestPolicyHeadersConfig] -> ShowS
$cshowList :: [OriginRequestPolicyHeadersConfig] -> ShowS
show :: OriginRequestPolicyHeadersConfig -> String
$cshow :: OriginRequestPolicyHeadersConfig -> String
showsPrec :: Int -> OriginRequestPolicyHeadersConfig -> ShowS
$cshowsPrec :: Int -> OriginRequestPolicyHeadersConfig -> ShowS
Prelude.Show, (forall x.
 OriginRequestPolicyHeadersConfig
 -> Rep OriginRequestPolicyHeadersConfig x)
-> (forall x.
    Rep OriginRequestPolicyHeadersConfig x
    -> OriginRequestPolicyHeadersConfig)
-> Generic OriginRequestPolicyHeadersConfig
forall x.
Rep OriginRequestPolicyHeadersConfig x
-> OriginRequestPolicyHeadersConfig
forall x.
OriginRequestPolicyHeadersConfig
-> Rep OriginRequestPolicyHeadersConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep OriginRequestPolicyHeadersConfig x
-> OriginRequestPolicyHeadersConfig
$cfrom :: forall x.
OriginRequestPolicyHeadersConfig
-> Rep OriginRequestPolicyHeadersConfig x
Prelude.Generic)

-- |
-- Create a value of 'OriginRequestPolicyHeadersConfig' 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', 'originRequestPolicyHeadersConfig_headers' - Undocumented member.
--
-- 'headerBehavior', 'originRequestPolicyHeadersConfig_headerBehavior' - Determines whether any HTTP headers are included in requests that
-- CloudFront sends to the origin. Valid values are:
--
-- -   @none@ – HTTP headers are not included in requests that CloudFront
--     sends to the origin. Even when this field is set to @none@, any
--     headers that are listed in a @CachePolicy@ /are/ included in origin
--     requests.
--
-- -   @whitelist@ – The HTTP headers that are listed in the @Headers@ type
--     are included in requests that CloudFront sends to the origin.
--
-- -   @allViewer@ – All HTTP headers in viewer requests are included in
--     requests that CloudFront sends to the origin.
--
-- -   @allViewerAndWhitelistCloudFront@ – All HTTP headers in viewer
--     requests and the additional CloudFront headers that are listed in
--     the @Headers@ type are included in requests that CloudFront sends to
--     the origin. The additional headers are added by CloudFront.
newOriginRequestPolicyHeadersConfig ::
  -- | 'headerBehavior'
  OriginRequestPolicyHeaderBehavior ->
  OriginRequestPolicyHeadersConfig
newOriginRequestPolicyHeadersConfig :: OriginRequestPolicyHeaderBehavior
-> OriginRequestPolicyHeadersConfig
newOriginRequestPolicyHeadersConfig OriginRequestPolicyHeaderBehavior
pHeaderBehavior_ =
  OriginRequestPolicyHeadersConfig' :: Maybe Headers
-> OriginRequestPolicyHeaderBehavior
-> OriginRequestPolicyHeadersConfig
OriginRequestPolicyHeadersConfig'
    { $sel:headers:OriginRequestPolicyHeadersConfig' :: Maybe Headers
headers =
        Maybe Headers
forall a. Maybe a
Prelude.Nothing,
      $sel:headerBehavior:OriginRequestPolicyHeadersConfig' :: OriginRequestPolicyHeaderBehavior
headerBehavior = OriginRequestPolicyHeaderBehavior
pHeaderBehavior_
    }

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

-- | Determines whether any HTTP headers are included in requests that
-- CloudFront sends to the origin. Valid values are:
--
-- -   @none@ – HTTP headers are not included in requests that CloudFront
--     sends to the origin. Even when this field is set to @none@, any
--     headers that are listed in a @CachePolicy@ /are/ included in origin
--     requests.
--
-- -   @whitelist@ – The HTTP headers that are listed in the @Headers@ type
--     are included in requests that CloudFront sends to the origin.
--
-- -   @allViewer@ – All HTTP headers in viewer requests are included in
--     requests that CloudFront sends to the origin.
--
-- -   @allViewerAndWhitelistCloudFront@ – All HTTP headers in viewer
--     requests and the additional CloudFront headers that are listed in
--     the @Headers@ type are included in requests that CloudFront sends to
--     the origin. The additional headers are added by CloudFront.
originRequestPolicyHeadersConfig_headerBehavior :: Lens.Lens' OriginRequestPolicyHeadersConfig OriginRequestPolicyHeaderBehavior
originRequestPolicyHeadersConfig_headerBehavior :: (OriginRequestPolicyHeaderBehavior
 -> f OriginRequestPolicyHeaderBehavior)
-> OriginRequestPolicyHeadersConfig
-> f OriginRequestPolicyHeadersConfig
originRequestPolicyHeadersConfig_headerBehavior = (OriginRequestPolicyHeadersConfig
 -> OriginRequestPolicyHeaderBehavior)
-> (OriginRequestPolicyHeadersConfig
    -> OriginRequestPolicyHeaderBehavior
    -> OriginRequestPolicyHeadersConfig)
-> Lens
     OriginRequestPolicyHeadersConfig
     OriginRequestPolicyHeadersConfig
     OriginRequestPolicyHeaderBehavior
     OriginRequestPolicyHeaderBehavior
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicyHeadersConfig' {OriginRequestPolicyHeaderBehavior
headerBehavior :: OriginRequestPolicyHeaderBehavior
$sel:headerBehavior:OriginRequestPolicyHeadersConfig' :: OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyHeaderBehavior
headerBehavior} -> OriginRequestPolicyHeaderBehavior
headerBehavior) (\s :: OriginRequestPolicyHeadersConfig
s@OriginRequestPolicyHeadersConfig' {} OriginRequestPolicyHeaderBehavior
a -> OriginRequestPolicyHeadersConfig
s {$sel:headerBehavior:OriginRequestPolicyHeadersConfig' :: OriginRequestPolicyHeaderBehavior
headerBehavior = OriginRequestPolicyHeaderBehavior
a} :: OriginRequestPolicyHeadersConfig)

instance
  Core.FromXML
    OriginRequestPolicyHeadersConfig
  where
  parseXML :: [Node] -> Either String OriginRequestPolicyHeadersConfig
parseXML [Node]
x =
    Maybe Headers
-> OriginRequestPolicyHeaderBehavior
-> OriginRequestPolicyHeadersConfig
OriginRequestPolicyHeadersConfig'
      (Maybe Headers
 -> OriginRequestPolicyHeaderBehavior
 -> OriginRequestPolicyHeadersConfig)
-> Either String (Maybe Headers)
-> Either
     String
     (OriginRequestPolicyHeaderBehavior
      -> OriginRequestPolicyHeadersConfig)
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
  (OriginRequestPolicyHeaderBehavior
   -> OriginRequestPolicyHeadersConfig)
-> Either String OriginRequestPolicyHeaderBehavior
-> Either String OriginRequestPolicyHeadersConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String OriginRequestPolicyHeaderBehavior
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"HeaderBehavior")

instance
  Prelude.Hashable
    OriginRequestPolicyHeadersConfig

instance
  Prelude.NFData
    OriginRequestPolicyHeadersConfig

instance Core.ToXML OriginRequestPolicyHeadersConfig where
  toXML :: OriginRequestPolicyHeadersConfig -> XML
toXML OriginRequestPolicyHeadersConfig' {Maybe Headers
OriginRequestPolicyHeaderBehavior
headerBehavior :: OriginRequestPolicyHeaderBehavior
headers :: Maybe Headers
$sel:headerBehavior:OriginRequestPolicyHeadersConfig' :: OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyHeaderBehavior
$sel:headers:OriginRequestPolicyHeadersConfig' :: OriginRequestPolicyHeadersConfig -> 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 -> OriginRequestPolicyHeaderBehavior -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= OriginRequestPolicyHeaderBehavior
headerBehavior
      ]