{-# 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.Lightsail.Types.HeaderObject
-- 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.Lightsail.Types.HeaderObject where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Lightsail.Types.ForwardValues
import Amazonka.Lightsail.Types.HeaderEnum
import qualified Amazonka.Prelude as Prelude

-- | Describes the request headers that a Lightsail distribution bases
-- caching on.
--
-- For the headers that you specify, your distribution caches separate
-- versions of the specified content based on the header values in viewer
-- requests. For example, suppose viewer requests for @logo.jpg@ contain a
-- custom @product@ header that has a value of either @acme@ or @apex@, and
-- you configure your distribution to cache your content based on values in
-- the @product@ header. Your distribution forwards the @product@ header to
-- the origin and caches the response from the origin once for each header
-- value.
--
-- /See:/ 'newHeaderObject' smart constructor.
data HeaderObject = HeaderObject'
  { -- | The specific headers to forward to your distribution\'s origin.
    HeaderObject -> Maybe [HeaderEnum]
headersAllowList :: Prelude.Maybe [HeaderEnum],
    -- | The headers that you want your distribution to forward to your origin
    -- and base caching on.
    --
    -- You can configure your distribution to do one of the following:
    --
    -- -   __@all@__ - Forward all headers to your origin.
    --
    -- -   __@none@__ - Forward only the default headers.
    --
    -- -   __@allow-list@__ - Forward only the headers you specify using the
    --     @headersAllowList@ parameter.
    HeaderObject -> Maybe ForwardValues
option :: Prelude.Maybe ForwardValues
  }
  deriving (HeaderObject -> HeaderObject -> Bool
(HeaderObject -> HeaderObject -> Bool)
-> (HeaderObject -> HeaderObject -> Bool) -> Eq HeaderObject
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HeaderObject -> HeaderObject -> Bool
$c/= :: HeaderObject -> HeaderObject -> Bool
== :: HeaderObject -> HeaderObject -> Bool
$c== :: HeaderObject -> HeaderObject -> Bool
Prelude.Eq, ReadPrec [HeaderObject]
ReadPrec HeaderObject
Int -> ReadS HeaderObject
ReadS [HeaderObject]
(Int -> ReadS HeaderObject)
-> ReadS [HeaderObject]
-> ReadPrec HeaderObject
-> ReadPrec [HeaderObject]
-> Read HeaderObject
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HeaderObject]
$creadListPrec :: ReadPrec [HeaderObject]
readPrec :: ReadPrec HeaderObject
$creadPrec :: ReadPrec HeaderObject
readList :: ReadS [HeaderObject]
$creadList :: ReadS [HeaderObject]
readsPrec :: Int -> ReadS HeaderObject
$creadsPrec :: Int -> ReadS HeaderObject
Prelude.Read, Int -> HeaderObject -> ShowS
[HeaderObject] -> ShowS
HeaderObject -> String
(Int -> HeaderObject -> ShowS)
-> (HeaderObject -> String)
-> ([HeaderObject] -> ShowS)
-> Show HeaderObject
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HeaderObject] -> ShowS
$cshowList :: [HeaderObject] -> ShowS
show :: HeaderObject -> String
$cshow :: HeaderObject -> String
showsPrec :: Int -> HeaderObject -> ShowS
$cshowsPrec :: Int -> HeaderObject -> ShowS
Prelude.Show, (forall x. HeaderObject -> Rep HeaderObject x)
-> (forall x. Rep HeaderObject x -> HeaderObject)
-> Generic HeaderObject
forall x. Rep HeaderObject x -> HeaderObject
forall x. HeaderObject -> Rep HeaderObject x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HeaderObject x -> HeaderObject
$cfrom :: forall x. HeaderObject -> Rep HeaderObject x
Prelude.Generic)

-- |
-- Create a value of 'HeaderObject' 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:
--
-- 'headersAllowList', 'headerObject_headersAllowList' - The specific headers to forward to your distribution\'s origin.
--
-- 'option', 'headerObject_option' - The headers that you want your distribution to forward to your origin
-- and base caching on.
--
-- You can configure your distribution to do one of the following:
--
-- -   __@all@__ - Forward all headers to your origin.
--
-- -   __@none@__ - Forward only the default headers.
--
-- -   __@allow-list@__ - Forward only the headers you specify using the
--     @headersAllowList@ parameter.
newHeaderObject ::
  HeaderObject
newHeaderObject :: HeaderObject
newHeaderObject =
  HeaderObject' :: Maybe [HeaderEnum] -> Maybe ForwardValues -> HeaderObject
HeaderObject'
    { $sel:headersAllowList:HeaderObject' :: Maybe [HeaderEnum]
headersAllowList = Maybe [HeaderEnum]
forall a. Maybe a
Prelude.Nothing,
      $sel:option:HeaderObject' :: Maybe ForwardValues
option = Maybe ForwardValues
forall a. Maybe a
Prelude.Nothing
    }

-- | The specific headers to forward to your distribution\'s origin.
headerObject_headersAllowList :: Lens.Lens' HeaderObject (Prelude.Maybe [HeaderEnum])
headerObject_headersAllowList :: (Maybe [HeaderEnum] -> f (Maybe [HeaderEnum]))
-> HeaderObject -> f HeaderObject
headerObject_headersAllowList = (HeaderObject -> Maybe [HeaderEnum])
-> (HeaderObject -> Maybe [HeaderEnum] -> HeaderObject)
-> Lens
     HeaderObject HeaderObject (Maybe [HeaderEnum]) (Maybe [HeaderEnum])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HeaderObject' {Maybe [HeaderEnum]
headersAllowList :: Maybe [HeaderEnum]
$sel:headersAllowList:HeaderObject' :: HeaderObject -> Maybe [HeaderEnum]
headersAllowList} -> Maybe [HeaderEnum]
headersAllowList) (\s :: HeaderObject
s@HeaderObject' {} Maybe [HeaderEnum]
a -> HeaderObject
s {$sel:headersAllowList:HeaderObject' :: Maybe [HeaderEnum]
headersAllowList = Maybe [HeaderEnum]
a} :: HeaderObject) ((Maybe [HeaderEnum] -> f (Maybe [HeaderEnum]))
 -> HeaderObject -> f HeaderObject)
-> ((Maybe [HeaderEnum] -> f (Maybe [HeaderEnum]))
    -> Maybe [HeaderEnum] -> f (Maybe [HeaderEnum]))
-> (Maybe [HeaderEnum] -> f (Maybe [HeaderEnum]))
-> HeaderObject
-> f HeaderObject
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [HeaderEnum] [HeaderEnum] [HeaderEnum] [HeaderEnum]
-> Iso
     (Maybe [HeaderEnum])
     (Maybe [HeaderEnum])
     (Maybe [HeaderEnum])
     (Maybe [HeaderEnum])
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 AnIso [HeaderEnum] [HeaderEnum] [HeaderEnum] [HeaderEnum]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The headers that you want your distribution to forward to your origin
-- and base caching on.
--
-- You can configure your distribution to do one of the following:
--
-- -   __@all@__ - Forward all headers to your origin.
--
-- -   __@none@__ - Forward only the default headers.
--
-- -   __@allow-list@__ - Forward only the headers you specify using the
--     @headersAllowList@ parameter.
headerObject_option :: Lens.Lens' HeaderObject (Prelude.Maybe ForwardValues)
headerObject_option :: (Maybe ForwardValues -> f (Maybe ForwardValues))
-> HeaderObject -> f HeaderObject
headerObject_option = (HeaderObject -> Maybe ForwardValues)
-> (HeaderObject -> Maybe ForwardValues -> HeaderObject)
-> Lens
     HeaderObject
     HeaderObject
     (Maybe ForwardValues)
     (Maybe ForwardValues)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HeaderObject' {Maybe ForwardValues
option :: Maybe ForwardValues
$sel:option:HeaderObject' :: HeaderObject -> Maybe ForwardValues
option} -> Maybe ForwardValues
option) (\s :: HeaderObject
s@HeaderObject' {} Maybe ForwardValues
a -> HeaderObject
s {$sel:option:HeaderObject' :: Maybe ForwardValues
option = Maybe ForwardValues
a} :: HeaderObject)

instance Core.FromJSON HeaderObject where
  parseJSON :: Value -> Parser HeaderObject
parseJSON =
    String
-> (Object -> Parser HeaderObject) -> Value -> Parser HeaderObject
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HeaderObject"
      ( \Object
x ->
          Maybe [HeaderEnum] -> Maybe ForwardValues -> HeaderObject
HeaderObject'
            (Maybe [HeaderEnum] -> Maybe ForwardValues -> HeaderObject)
-> Parser (Maybe [HeaderEnum])
-> Parser (Maybe ForwardValues -> HeaderObject)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> ( Object
x Object -> Text -> Parser (Maybe (Maybe [HeaderEnum]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"headersAllowList"
                            Parser (Maybe (Maybe [HeaderEnum]))
-> Maybe [HeaderEnum] -> Parser (Maybe [HeaderEnum])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [HeaderEnum]
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser (Maybe ForwardValues -> HeaderObject)
-> Parser (Maybe ForwardValues) -> Parser HeaderObject
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ForwardValues)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"option")
      )

instance Prelude.Hashable HeaderObject

instance Prelude.NFData HeaderObject

instance Core.ToJSON HeaderObject where
  toJSON :: HeaderObject -> Value
toJSON HeaderObject' {Maybe [HeaderEnum]
Maybe ForwardValues
option :: Maybe ForwardValues
headersAllowList :: Maybe [HeaderEnum]
$sel:option:HeaderObject' :: HeaderObject -> Maybe ForwardValues
$sel:headersAllowList:HeaderObject' :: HeaderObject -> Maybe [HeaderEnum]
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"headersAllowList" Text -> [HeaderEnum] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              ([HeaderEnum] -> Pair) -> Maybe [HeaderEnum] -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe [HeaderEnum]
headersAllowList,
            (Text
"option" Text -> ForwardValues -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (ForwardValues -> Pair) -> Maybe ForwardValues -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe ForwardValues
option
          ]
      )