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

import Amazonka.CloudFront.Types.OriginRequestPolicyCookiesConfig
import Amazonka.CloudFront.Types.OriginRequestPolicyHeadersConfig
import Amazonka.CloudFront.Types.OriginRequestPolicyQueryStringsConfig
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An origin request policy configuration.
--
-- This configuration determines the values that CloudFront includes in
-- requests that it sends to the origin. Each request that CloudFront sends
-- to the origin includes the following:
--
-- -   The request body and the URL path (without the domain name) from the
--     viewer request.
--
-- -   The headers that CloudFront automatically includes in every origin
--     request, including @Host@, @User-Agent@, and @X-Amz-Cf-Id@.
--
-- -   All HTTP headers, cookies, and URL query strings that are specified
--     in the cache policy or the origin request policy. These can include
--     items from the viewer request and, in the case of headers,
--     additional ones that are added by CloudFront.
--
-- CloudFront sends a request when it can’t find an object in its cache
-- that matches the request. If you want to send values to the origin and
-- also include them in the cache key, use @CachePolicy@.
--
-- /See:/ 'newOriginRequestPolicyConfig' smart constructor.
data OriginRequestPolicyConfig = OriginRequestPolicyConfig'
  { -- | A comment to describe the origin request policy. The comment cannot be
    -- longer than 128 characters.
    OriginRequestPolicyConfig -> Maybe Text
comment :: Prelude.Maybe Prelude.Text,
    -- | A unique name to identify the origin request policy.
    OriginRequestPolicyConfig -> Text
name :: Prelude.Text,
    -- | The HTTP headers to include in origin requests. These can include
    -- headers from viewer requests and additional headers added by CloudFront.
    OriginRequestPolicyConfig -> OriginRequestPolicyHeadersConfig
headersConfig :: OriginRequestPolicyHeadersConfig,
    -- | The cookies from viewer requests to include in origin requests.
    OriginRequestPolicyConfig -> OriginRequestPolicyCookiesConfig
cookiesConfig :: OriginRequestPolicyCookiesConfig,
    -- | The URL query strings from viewer requests to include in origin
    -- requests.
    OriginRequestPolicyConfig -> OriginRequestPolicyQueryStringsConfig
queryStringsConfig :: OriginRequestPolicyQueryStringsConfig
  }
  deriving (OriginRequestPolicyConfig -> OriginRequestPolicyConfig -> Bool
(OriginRequestPolicyConfig -> OriginRequestPolicyConfig -> Bool)
-> (OriginRequestPolicyConfig -> OriginRequestPolicyConfig -> Bool)
-> Eq OriginRequestPolicyConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OriginRequestPolicyConfig -> OriginRequestPolicyConfig -> Bool
$c/= :: OriginRequestPolicyConfig -> OriginRequestPolicyConfig -> Bool
== :: OriginRequestPolicyConfig -> OriginRequestPolicyConfig -> Bool
$c== :: OriginRequestPolicyConfig -> OriginRequestPolicyConfig -> Bool
Prelude.Eq, ReadPrec [OriginRequestPolicyConfig]
ReadPrec OriginRequestPolicyConfig
Int -> ReadS OriginRequestPolicyConfig
ReadS [OriginRequestPolicyConfig]
(Int -> ReadS OriginRequestPolicyConfig)
-> ReadS [OriginRequestPolicyConfig]
-> ReadPrec OriginRequestPolicyConfig
-> ReadPrec [OriginRequestPolicyConfig]
-> Read OriginRequestPolicyConfig
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OriginRequestPolicyConfig]
$creadListPrec :: ReadPrec [OriginRequestPolicyConfig]
readPrec :: ReadPrec OriginRequestPolicyConfig
$creadPrec :: ReadPrec OriginRequestPolicyConfig
readList :: ReadS [OriginRequestPolicyConfig]
$creadList :: ReadS [OriginRequestPolicyConfig]
readsPrec :: Int -> ReadS OriginRequestPolicyConfig
$creadsPrec :: Int -> ReadS OriginRequestPolicyConfig
Prelude.Read, Int -> OriginRequestPolicyConfig -> ShowS
[OriginRequestPolicyConfig] -> ShowS
OriginRequestPolicyConfig -> String
(Int -> OriginRequestPolicyConfig -> ShowS)
-> (OriginRequestPolicyConfig -> String)
-> ([OriginRequestPolicyConfig] -> ShowS)
-> Show OriginRequestPolicyConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OriginRequestPolicyConfig] -> ShowS
$cshowList :: [OriginRequestPolicyConfig] -> ShowS
show :: OriginRequestPolicyConfig -> String
$cshow :: OriginRequestPolicyConfig -> String
showsPrec :: Int -> OriginRequestPolicyConfig -> ShowS
$cshowsPrec :: Int -> OriginRequestPolicyConfig -> ShowS
Prelude.Show, (forall x.
 OriginRequestPolicyConfig -> Rep OriginRequestPolicyConfig x)
-> (forall x.
    Rep OriginRequestPolicyConfig x -> OriginRequestPolicyConfig)
-> Generic OriginRequestPolicyConfig
forall x.
Rep OriginRequestPolicyConfig x -> OriginRequestPolicyConfig
forall x.
OriginRequestPolicyConfig -> Rep OriginRequestPolicyConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep OriginRequestPolicyConfig x -> OriginRequestPolicyConfig
$cfrom :: forall x.
OriginRequestPolicyConfig -> Rep OriginRequestPolicyConfig x
Prelude.Generic)

-- |
-- Create a value of 'OriginRequestPolicyConfig' 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:
--
-- 'comment', 'originRequestPolicyConfig_comment' - A comment to describe the origin request policy. The comment cannot be
-- longer than 128 characters.
--
-- 'name', 'originRequestPolicyConfig_name' - A unique name to identify the origin request policy.
--
-- 'headersConfig', 'originRequestPolicyConfig_headersConfig' - The HTTP headers to include in origin requests. These can include
-- headers from viewer requests and additional headers added by CloudFront.
--
-- 'cookiesConfig', 'originRequestPolicyConfig_cookiesConfig' - The cookies from viewer requests to include in origin requests.
--
-- 'queryStringsConfig', 'originRequestPolicyConfig_queryStringsConfig' - The URL query strings from viewer requests to include in origin
-- requests.
newOriginRequestPolicyConfig ::
  -- | 'name'
  Prelude.Text ->
  -- | 'headersConfig'
  OriginRequestPolicyHeadersConfig ->
  -- | 'cookiesConfig'
  OriginRequestPolicyCookiesConfig ->
  -- | 'queryStringsConfig'
  OriginRequestPolicyQueryStringsConfig ->
  OriginRequestPolicyConfig
newOriginRequestPolicyConfig :: Text
-> OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyQueryStringsConfig
-> OriginRequestPolicyConfig
newOriginRequestPolicyConfig
  Text
pName_
  OriginRequestPolicyHeadersConfig
pHeadersConfig_
  OriginRequestPolicyCookiesConfig
pCookiesConfig_
  OriginRequestPolicyQueryStringsConfig
pQueryStringsConfig_ =
    OriginRequestPolicyConfig' :: Maybe Text
-> Text
-> OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyQueryStringsConfig
-> OriginRequestPolicyConfig
OriginRequestPolicyConfig'
      { $sel:comment:OriginRequestPolicyConfig' :: Maybe Text
comment =
          Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:name:OriginRequestPolicyConfig' :: Text
name = Text
pName_,
        $sel:headersConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyHeadersConfig
headersConfig = OriginRequestPolicyHeadersConfig
pHeadersConfig_,
        $sel:cookiesConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyCookiesConfig
cookiesConfig = OriginRequestPolicyCookiesConfig
pCookiesConfig_,
        $sel:queryStringsConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyQueryStringsConfig
queryStringsConfig = OriginRequestPolicyQueryStringsConfig
pQueryStringsConfig_
      }

-- | A comment to describe the origin request policy. The comment cannot be
-- longer than 128 characters.
originRequestPolicyConfig_comment :: Lens.Lens' OriginRequestPolicyConfig (Prelude.Maybe Prelude.Text)
originRequestPolicyConfig_comment :: (Maybe Text -> f (Maybe Text))
-> OriginRequestPolicyConfig -> f OriginRequestPolicyConfig
originRequestPolicyConfig_comment = (OriginRequestPolicyConfig -> Maybe Text)
-> (OriginRequestPolicyConfig
    -> Maybe Text -> OriginRequestPolicyConfig)
-> Lens
     OriginRequestPolicyConfig
     OriginRequestPolicyConfig
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicyConfig' {Maybe Text
comment :: Maybe Text
$sel:comment:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> Maybe Text
comment} -> Maybe Text
comment) (\s :: OriginRequestPolicyConfig
s@OriginRequestPolicyConfig' {} Maybe Text
a -> OriginRequestPolicyConfig
s {$sel:comment:OriginRequestPolicyConfig' :: Maybe Text
comment = Maybe Text
a} :: OriginRequestPolicyConfig)

-- | A unique name to identify the origin request policy.
originRequestPolicyConfig_name :: Lens.Lens' OriginRequestPolicyConfig Prelude.Text
originRequestPolicyConfig_name :: (Text -> f Text)
-> OriginRequestPolicyConfig -> f OriginRequestPolicyConfig
originRequestPolicyConfig_name = (OriginRequestPolicyConfig -> Text)
-> (OriginRequestPolicyConfig -> Text -> OriginRequestPolicyConfig)
-> Lens
     OriginRequestPolicyConfig OriginRequestPolicyConfig Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicyConfig' {Text
name :: Text
$sel:name:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> Text
name} -> Text
name) (\s :: OriginRequestPolicyConfig
s@OriginRequestPolicyConfig' {} Text
a -> OriginRequestPolicyConfig
s {$sel:name:OriginRequestPolicyConfig' :: Text
name = Text
a} :: OriginRequestPolicyConfig)

-- | The HTTP headers to include in origin requests. These can include
-- headers from viewer requests and additional headers added by CloudFront.
originRequestPolicyConfig_headersConfig :: Lens.Lens' OriginRequestPolicyConfig OriginRequestPolicyHeadersConfig
originRequestPolicyConfig_headersConfig :: (OriginRequestPolicyHeadersConfig
 -> f OriginRequestPolicyHeadersConfig)
-> OriginRequestPolicyConfig -> f OriginRequestPolicyConfig
originRequestPolicyConfig_headersConfig = (OriginRequestPolicyConfig -> OriginRequestPolicyHeadersConfig)
-> (OriginRequestPolicyConfig
    -> OriginRequestPolicyHeadersConfig -> OriginRequestPolicyConfig)
-> Lens
     OriginRequestPolicyConfig
     OriginRequestPolicyConfig
     OriginRequestPolicyHeadersConfig
     OriginRequestPolicyHeadersConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicyConfig' {OriginRequestPolicyHeadersConfig
headersConfig :: OriginRequestPolicyHeadersConfig
$sel:headersConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> OriginRequestPolicyHeadersConfig
headersConfig} -> OriginRequestPolicyHeadersConfig
headersConfig) (\s :: OriginRequestPolicyConfig
s@OriginRequestPolicyConfig' {} OriginRequestPolicyHeadersConfig
a -> OriginRequestPolicyConfig
s {$sel:headersConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyHeadersConfig
headersConfig = OriginRequestPolicyHeadersConfig
a} :: OriginRequestPolicyConfig)

-- | The cookies from viewer requests to include in origin requests.
originRequestPolicyConfig_cookiesConfig :: Lens.Lens' OriginRequestPolicyConfig OriginRequestPolicyCookiesConfig
originRequestPolicyConfig_cookiesConfig :: (OriginRequestPolicyCookiesConfig
 -> f OriginRequestPolicyCookiesConfig)
-> OriginRequestPolicyConfig -> f OriginRequestPolicyConfig
originRequestPolicyConfig_cookiesConfig = (OriginRequestPolicyConfig -> OriginRequestPolicyCookiesConfig)
-> (OriginRequestPolicyConfig
    -> OriginRequestPolicyCookiesConfig -> OriginRequestPolicyConfig)
-> Lens
     OriginRequestPolicyConfig
     OriginRequestPolicyConfig
     OriginRequestPolicyCookiesConfig
     OriginRequestPolicyCookiesConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicyConfig' {OriginRequestPolicyCookiesConfig
cookiesConfig :: OriginRequestPolicyCookiesConfig
$sel:cookiesConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> OriginRequestPolicyCookiesConfig
cookiesConfig} -> OriginRequestPolicyCookiesConfig
cookiesConfig) (\s :: OriginRequestPolicyConfig
s@OriginRequestPolicyConfig' {} OriginRequestPolicyCookiesConfig
a -> OriginRequestPolicyConfig
s {$sel:cookiesConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyCookiesConfig
cookiesConfig = OriginRequestPolicyCookiesConfig
a} :: OriginRequestPolicyConfig)

-- | The URL query strings from viewer requests to include in origin
-- requests.
originRequestPolicyConfig_queryStringsConfig :: Lens.Lens' OriginRequestPolicyConfig OriginRequestPolicyQueryStringsConfig
originRequestPolicyConfig_queryStringsConfig :: (OriginRequestPolicyQueryStringsConfig
 -> f OriginRequestPolicyQueryStringsConfig)
-> OriginRequestPolicyConfig -> f OriginRequestPolicyConfig
originRequestPolicyConfig_queryStringsConfig = (OriginRequestPolicyConfig
 -> OriginRequestPolicyQueryStringsConfig)
-> (OriginRequestPolicyConfig
    -> OriginRequestPolicyQueryStringsConfig
    -> OriginRequestPolicyConfig)
-> Lens
     OriginRequestPolicyConfig
     OriginRequestPolicyConfig
     OriginRequestPolicyQueryStringsConfig
     OriginRequestPolicyQueryStringsConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicyConfig' {OriginRequestPolicyQueryStringsConfig
queryStringsConfig :: OriginRequestPolicyQueryStringsConfig
$sel:queryStringsConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> OriginRequestPolicyQueryStringsConfig
queryStringsConfig} -> OriginRequestPolicyQueryStringsConfig
queryStringsConfig) (\s :: OriginRequestPolicyConfig
s@OriginRequestPolicyConfig' {} OriginRequestPolicyQueryStringsConfig
a -> OriginRequestPolicyConfig
s {$sel:queryStringsConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyQueryStringsConfig
queryStringsConfig = OriginRequestPolicyQueryStringsConfig
a} :: OriginRequestPolicyConfig)

instance Core.FromXML OriginRequestPolicyConfig where
  parseXML :: [Node] -> Either String OriginRequestPolicyConfig
parseXML [Node]
x =
    Maybe Text
-> Text
-> OriginRequestPolicyHeadersConfig
-> OriginRequestPolicyCookiesConfig
-> OriginRequestPolicyQueryStringsConfig
-> OriginRequestPolicyConfig
OriginRequestPolicyConfig'
      (Maybe Text
 -> Text
 -> OriginRequestPolicyHeadersConfig
 -> OriginRequestPolicyCookiesConfig
 -> OriginRequestPolicyQueryStringsConfig
 -> OriginRequestPolicyConfig)
-> Either String (Maybe Text)
-> Either
     String
     (Text
      -> OriginRequestPolicyHeadersConfig
      -> OriginRequestPolicyCookiesConfig
      -> OriginRequestPolicyQueryStringsConfig
      -> OriginRequestPolicyConfig)
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
"Comment")
      Either
  String
  (Text
   -> OriginRequestPolicyHeadersConfig
   -> OriginRequestPolicyCookiesConfig
   -> OriginRequestPolicyQueryStringsConfig
   -> OriginRequestPolicyConfig)
-> Either String Text
-> Either
     String
     (OriginRequestPolicyHeadersConfig
      -> OriginRequestPolicyCookiesConfig
      -> OriginRequestPolicyQueryStringsConfig
      -> OriginRequestPolicyConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String Text
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"Name")
      Either
  String
  (OriginRequestPolicyHeadersConfig
   -> OriginRequestPolicyCookiesConfig
   -> OriginRequestPolicyQueryStringsConfig
   -> OriginRequestPolicyConfig)
-> Either String OriginRequestPolicyHeadersConfig
-> Either
     String
     (OriginRequestPolicyCookiesConfig
      -> OriginRequestPolicyQueryStringsConfig
      -> OriginRequestPolicyConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String OriginRequestPolicyHeadersConfig
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"HeadersConfig")
      Either
  String
  (OriginRequestPolicyCookiesConfig
   -> OriginRequestPolicyQueryStringsConfig
   -> OriginRequestPolicyConfig)
-> Either String OriginRequestPolicyCookiesConfig
-> Either
     String
     (OriginRequestPolicyQueryStringsConfig
      -> OriginRequestPolicyConfig)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String OriginRequestPolicyCookiesConfig
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"CookiesConfig")
      Either
  String
  (OriginRequestPolicyQueryStringsConfig
   -> OriginRequestPolicyConfig)
-> Either String OriginRequestPolicyQueryStringsConfig
-> Either String OriginRequestPolicyConfig
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node]
-> Text -> Either String OriginRequestPolicyQueryStringsConfig
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"QueryStringsConfig")

instance Prelude.Hashable OriginRequestPolicyConfig

instance Prelude.NFData OriginRequestPolicyConfig

instance Core.ToXML OriginRequestPolicyConfig where
  toXML :: OriginRequestPolicyConfig -> XML
toXML OriginRequestPolicyConfig' {Maybe Text
Text
OriginRequestPolicyCookiesConfig
OriginRequestPolicyHeadersConfig
OriginRequestPolicyQueryStringsConfig
queryStringsConfig :: OriginRequestPolicyQueryStringsConfig
cookiesConfig :: OriginRequestPolicyCookiesConfig
headersConfig :: OriginRequestPolicyHeadersConfig
name :: Text
comment :: Maybe Text
$sel:queryStringsConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> OriginRequestPolicyQueryStringsConfig
$sel:cookiesConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> OriginRequestPolicyCookiesConfig
$sel:headersConfig:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> OriginRequestPolicyHeadersConfig
$sel:name:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> Text
$sel:comment:OriginRequestPolicyConfig' :: OriginRequestPolicyConfig -> Maybe Text
..} =
    [XML] -> XML
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ Name
"Comment" Name -> Maybe Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Maybe Text
comment,
        Name
"Name" Name -> Text -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= Text
name,
        Name
"HeadersConfig" Name -> OriginRequestPolicyHeadersConfig -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= OriginRequestPolicyHeadersConfig
headersConfig,
        Name
"CookiesConfig" Name -> OriginRequestPolicyCookiesConfig -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= OriginRequestPolicyCookiesConfig
cookiesConfig,
        Name
"QueryStringsConfig" Name -> OriginRequestPolicyQueryStringsConfig -> XML
forall a. ToXML a => Name -> a -> XML
Core.@= OriginRequestPolicyQueryStringsConfig
queryStringsConfig
      ]