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

import Amazonka.CloudFront.Types.OriginRequestPolicyConfig
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | An origin request policy.
--
-- When it’s attached to a cache behavior, the origin request policy
-- 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:/ 'newOriginRequestPolicy' smart constructor.
data OriginRequestPolicy = OriginRequestPolicy'
  { -- | The unique identifier for the origin request policy.
    OriginRequestPolicy -> Text
id :: Prelude.Text,
    -- | The date and time when the origin request policy was last modified.
    OriginRequestPolicy -> ISO8601
lastModifiedTime :: Core.ISO8601,
    -- | The origin request policy configuration.
    OriginRequestPolicy -> OriginRequestPolicyConfig
originRequestPolicyConfig :: OriginRequestPolicyConfig
  }
  deriving (OriginRequestPolicy -> OriginRequestPolicy -> Bool
(OriginRequestPolicy -> OriginRequestPolicy -> Bool)
-> (OriginRequestPolicy -> OriginRequestPolicy -> Bool)
-> Eq OriginRequestPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OriginRequestPolicy -> OriginRequestPolicy -> Bool
$c/= :: OriginRequestPolicy -> OriginRequestPolicy -> Bool
== :: OriginRequestPolicy -> OriginRequestPolicy -> Bool
$c== :: OriginRequestPolicy -> OriginRequestPolicy -> Bool
Prelude.Eq, ReadPrec [OriginRequestPolicy]
ReadPrec OriginRequestPolicy
Int -> ReadS OriginRequestPolicy
ReadS [OriginRequestPolicy]
(Int -> ReadS OriginRequestPolicy)
-> ReadS [OriginRequestPolicy]
-> ReadPrec OriginRequestPolicy
-> ReadPrec [OriginRequestPolicy]
-> Read OriginRequestPolicy
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OriginRequestPolicy]
$creadListPrec :: ReadPrec [OriginRequestPolicy]
readPrec :: ReadPrec OriginRequestPolicy
$creadPrec :: ReadPrec OriginRequestPolicy
readList :: ReadS [OriginRequestPolicy]
$creadList :: ReadS [OriginRequestPolicy]
readsPrec :: Int -> ReadS OriginRequestPolicy
$creadsPrec :: Int -> ReadS OriginRequestPolicy
Prelude.Read, Int -> OriginRequestPolicy -> ShowS
[OriginRequestPolicy] -> ShowS
OriginRequestPolicy -> String
(Int -> OriginRequestPolicy -> ShowS)
-> (OriginRequestPolicy -> String)
-> ([OriginRequestPolicy] -> ShowS)
-> Show OriginRequestPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OriginRequestPolicy] -> ShowS
$cshowList :: [OriginRequestPolicy] -> ShowS
show :: OriginRequestPolicy -> String
$cshow :: OriginRequestPolicy -> String
showsPrec :: Int -> OriginRequestPolicy -> ShowS
$cshowsPrec :: Int -> OriginRequestPolicy -> ShowS
Prelude.Show, (forall x. OriginRequestPolicy -> Rep OriginRequestPolicy x)
-> (forall x. Rep OriginRequestPolicy x -> OriginRequestPolicy)
-> Generic OriginRequestPolicy
forall x. Rep OriginRequestPolicy x -> OriginRequestPolicy
forall x. OriginRequestPolicy -> Rep OriginRequestPolicy x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OriginRequestPolicy x -> OriginRequestPolicy
$cfrom :: forall x. OriginRequestPolicy -> Rep OriginRequestPolicy x
Prelude.Generic)

-- |
-- Create a value of 'OriginRequestPolicy' 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:
--
-- 'id', 'originRequestPolicy_id' - The unique identifier for the origin request policy.
--
-- 'lastModifiedTime', 'originRequestPolicy_lastModifiedTime' - The date and time when the origin request policy was last modified.
--
-- 'originRequestPolicyConfig', 'originRequestPolicy_originRequestPolicyConfig' - The origin request policy configuration.
newOriginRequestPolicy ::
  -- | 'id'
  Prelude.Text ->
  -- | 'lastModifiedTime'
  Prelude.UTCTime ->
  -- | 'originRequestPolicyConfig'
  OriginRequestPolicyConfig ->
  OriginRequestPolicy
newOriginRequestPolicy :: Text -> UTCTime -> OriginRequestPolicyConfig -> OriginRequestPolicy
newOriginRequestPolicy
  Text
pId_
  UTCTime
pLastModifiedTime_
  OriginRequestPolicyConfig
pOriginRequestPolicyConfig_ =
    OriginRequestPolicy' :: Text -> ISO8601 -> OriginRequestPolicyConfig -> OriginRequestPolicy
OriginRequestPolicy'
      { $sel:id:OriginRequestPolicy' :: Text
id = Text
pId_,
        $sel:lastModifiedTime:OriginRequestPolicy' :: ISO8601
lastModifiedTime =
          Tagged UTCTime (Identity UTCTime)
-> Tagged ISO8601 (Identity ISO8601)
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time (Tagged UTCTime (Identity UTCTime)
 -> Tagged ISO8601 (Identity ISO8601))
-> UTCTime -> ISO8601
forall t b. AReview t b -> b -> t
Lens.# UTCTime
pLastModifiedTime_,
        $sel:originRequestPolicyConfig:OriginRequestPolicy' :: OriginRequestPolicyConfig
originRequestPolicyConfig =
          OriginRequestPolicyConfig
pOriginRequestPolicyConfig_
      }

-- | The unique identifier for the origin request policy.
originRequestPolicy_id :: Lens.Lens' OriginRequestPolicy Prelude.Text
originRequestPolicy_id :: (Text -> f Text) -> OriginRequestPolicy -> f OriginRequestPolicy
originRequestPolicy_id = (OriginRequestPolicy -> Text)
-> (OriginRequestPolicy -> Text -> OriginRequestPolicy)
-> Lens OriginRequestPolicy OriginRequestPolicy Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicy' {Text
id :: Text
$sel:id:OriginRequestPolicy' :: OriginRequestPolicy -> Text
id} -> Text
id) (\s :: OriginRequestPolicy
s@OriginRequestPolicy' {} Text
a -> OriginRequestPolicy
s {$sel:id:OriginRequestPolicy' :: Text
id = Text
a} :: OriginRequestPolicy)

-- | The date and time when the origin request policy was last modified.
originRequestPolicy_lastModifiedTime :: Lens.Lens' OriginRequestPolicy Prelude.UTCTime
originRequestPolicy_lastModifiedTime :: (UTCTime -> f UTCTime)
-> OriginRequestPolicy -> f OriginRequestPolicy
originRequestPolicy_lastModifiedTime = (OriginRequestPolicy -> ISO8601)
-> (OriginRequestPolicy -> ISO8601 -> OriginRequestPolicy)
-> Lens OriginRequestPolicy OriginRequestPolicy ISO8601 ISO8601
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicy' {ISO8601
lastModifiedTime :: ISO8601
$sel:lastModifiedTime:OriginRequestPolicy' :: OriginRequestPolicy -> ISO8601
lastModifiedTime} -> ISO8601
lastModifiedTime) (\s :: OriginRequestPolicy
s@OriginRequestPolicy' {} ISO8601
a -> OriginRequestPolicy
s {$sel:lastModifiedTime:OriginRequestPolicy' :: ISO8601
lastModifiedTime = ISO8601
a} :: OriginRequestPolicy) ((ISO8601 -> f ISO8601)
 -> OriginRequestPolicy -> f OriginRequestPolicy)
-> ((UTCTime -> f UTCTime) -> ISO8601 -> f ISO8601)
-> (UTCTime -> f UTCTime)
-> OriginRequestPolicy
-> f OriginRequestPolicy
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (UTCTime -> f UTCTime) -> ISO8601 -> f ISO8601
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The origin request policy configuration.
originRequestPolicy_originRequestPolicyConfig :: Lens.Lens' OriginRequestPolicy OriginRequestPolicyConfig
originRequestPolicy_originRequestPolicyConfig :: (OriginRequestPolicyConfig -> f OriginRequestPolicyConfig)
-> OriginRequestPolicy -> f OriginRequestPolicy
originRequestPolicy_originRequestPolicyConfig = (OriginRequestPolicy -> OriginRequestPolicyConfig)
-> (OriginRequestPolicy
    -> OriginRequestPolicyConfig -> OriginRequestPolicy)
-> Lens
     OriginRequestPolicy
     OriginRequestPolicy
     OriginRequestPolicyConfig
     OriginRequestPolicyConfig
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginRequestPolicy' {OriginRequestPolicyConfig
originRequestPolicyConfig :: OriginRequestPolicyConfig
$sel:originRequestPolicyConfig:OriginRequestPolicy' :: OriginRequestPolicy -> OriginRequestPolicyConfig
originRequestPolicyConfig} -> OriginRequestPolicyConfig
originRequestPolicyConfig) (\s :: OriginRequestPolicy
s@OriginRequestPolicy' {} OriginRequestPolicyConfig
a -> OriginRequestPolicy
s {$sel:originRequestPolicyConfig:OriginRequestPolicy' :: OriginRequestPolicyConfig
originRequestPolicyConfig = OriginRequestPolicyConfig
a} :: OriginRequestPolicy)

instance Core.FromXML OriginRequestPolicy where
  parseXML :: [Node] -> Either String OriginRequestPolicy
parseXML [Node]
x =
    Text -> ISO8601 -> OriginRequestPolicyConfig -> OriginRequestPolicy
OriginRequestPolicy'
      (Text
 -> ISO8601 -> OriginRequestPolicyConfig -> OriginRequestPolicy)
-> Either String Text
-> Either
     String
     (ISO8601 -> OriginRequestPolicyConfig -> OriginRequestPolicy)
forall (f :: * -> *) a b. Functor 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
"Id")
      Either
  String
  (ISO8601 -> OriginRequestPolicyConfig -> OriginRequestPolicy)
-> Either String ISO8601
-> Either String (OriginRequestPolicyConfig -> OriginRequestPolicy)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String ISO8601
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"LastModifiedTime")
      Either String (OriginRequestPolicyConfig -> OriginRequestPolicy)
-> Either String OriginRequestPolicyConfig
-> Either String OriginRequestPolicy
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ([Node]
x [Node] -> Text -> Either String OriginRequestPolicyConfig
forall a. FromXML a => [Node] -> Text -> Either String a
Core..@ Text
"OriginRequestPolicyConfig")

instance Prelude.Hashable OriginRequestPolicy

instance Prelude.NFData OriginRequestPolicy