{-# 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.WAFV2.Types.Body
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.WAFV2.Types.Body where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import qualified Amazonka.Prelude as Prelude
import Amazonka.WAFV2.Types.OversizeHandling

-- | Inspect the body of the web request. The body immediately follows the
-- request headers.
--
-- This is used to indicate the web request component to inspect, in the
-- FieldToMatch specification.
--
-- /See:/ 'newBody' smart constructor.
data Body = Body'
  { -- | What WAF should do if the body is larger than WAF can inspect. WAF does
    -- not support inspecting the entire contents of the body of a web request
    -- when the body exceeds 8 KB (8192 bytes). Only the first 8 KB of the
    -- request body are forwarded to WAF by the underlying host service.
    --
    -- The options for oversize handling are the following:
    --
    -- -   @CONTINUE@ - Inspect the body normally, according to the rule
    --     inspection criteria.
    --
    -- -   @MATCH@ - Treat the web request as matching the rule statement. WAF
    --     applies the rule action to the request.
    --
    -- -   @NO_MATCH@ - Treat the web request as not matching the rule
    --     statement.
    --
    -- You can combine the @MATCH@ or @NO_MATCH@ settings for oversize handling
    -- with your rule and web ACL action settings, so that you block any
    -- request whose body is over 8 KB.
    --
    -- Default: @CONTINUE@
    Body -> Maybe OversizeHandling
oversizeHandling :: Prelude.Maybe OversizeHandling
  }
  deriving (Body -> Body -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Body -> Body -> Bool
$c/= :: Body -> Body -> Bool
== :: Body -> Body -> Bool
$c== :: Body -> Body -> Bool
Prelude.Eq, ReadPrec [Body]
ReadPrec Body
Int -> ReadS Body
ReadS [Body]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Body]
$creadListPrec :: ReadPrec [Body]
readPrec :: ReadPrec Body
$creadPrec :: ReadPrec Body
readList :: ReadS [Body]
$creadList :: ReadS [Body]
readsPrec :: Int -> ReadS Body
$creadsPrec :: Int -> ReadS Body
Prelude.Read, Int -> Body -> ShowS
[Body] -> ShowS
Body -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Body] -> ShowS
$cshowList :: [Body] -> ShowS
show :: Body -> String
$cshow :: Body -> String
showsPrec :: Int -> Body -> ShowS
$cshowsPrec :: Int -> Body -> ShowS
Prelude.Show, forall x. Rep Body x -> Body
forall x. Body -> Rep Body x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Body x -> Body
$cfrom :: forall x. Body -> Rep Body x
Prelude.Generic)

-- |
-- Create a value of 'Body' 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:
--
-- 'oversizeHandling', 'body_oversizeHandling' - What WAF should do if the body is larger than WAF can inspect. WAF does
-- not support inspecting the entire contents of the body of a web request
-- when the body exceeds 8 KB (8192 bytes). Only the first 8 KB of the
-- request body are forwarded to WAF by the underlying host service.
--
-- The options for oversize handling are the following:
--
-- -   @CONTINUE@ - Inspect the body normally, according to the rule
--     inspection criteria.
--
-- -   @MATCH@ - Treat the web request as matching the rule statement. WAF
--     applies the rule action to the request.
--
-- -   @NO_MATCH@ - Treat the web request as not matching the rule
--     statement.
--
-- You can combine the @MATCH@ or @NO_MATCH@ settings for oversize handling
-- with your rule and web ACL action settings, so that you block any
-- request whose body is over 8 KB.
--
-- Default: @CONTINUE@
newBody ::
  Body
newBody :: Body
newBody = Body' {$sel:oversizeHandling:Body' :: Maybe OversizeHandling
oversizeHandling = forall a. Maybe a
Prelude.Nothing}

-- | What WAF should do if the body is larger than WAF can inspect. WAF does
-- not support inspecting the entire contents of the body of a web request
-- when the body exceeds 8 KB (8192 bytes). Only the first 8 KB of the
-- request body are forwarded to WAF by the underlying host service.
--
-- The options for oversize handling are the following:
--
-- -   @CONTINUE@ - Inspect the body normally, according to the rule
--     inspection criteria.
--
-- -   @MATCH@ - Treat the web request as matching the rule statement. WAF
--     applies the rule action to the request.
--
-- -   @NO_MATCH@ - Treat the web request as not matching the rule
--     statement.
--
-- You can combine the @MATCH@ or @NO_MATCH@ settings for oversize handling
-- with your rule and web ACL action settings, so that you block any
-- request whose body is over 8 KB.
--
-- Default: @CONTINUE@
body_oversizeHandling :: Lens.Lens' Body (Prelude.Maybe OversizeHandling)
body_oversizeHandling :: Lens' Body (Maybe OversizeHandling)
body_oversizeHandling = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Body' {Maybe OversizeHandling
oversizeHandling :: Maybe OversizeHandling
$sel:oversizeHandling:Body' :: Body -> Maybe OversizeHandling
oversizeHandling} -> Maybe OversizeHandling
oversizeHandling) (\s :: Body
s@Body' {} Maybe OversizeHandling
a -> Body
s {$sel:oversizeHandling:Body' :: Maybe OversizeHandling
oversizeHandling = Maybe OversizeHandling
a} :: Body)

instance Data.FromJSON Body where
  parseJSON :: Value -> Parser Body
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Body"
      ( \Object
x ->
          Maybe OversizeHandling -> Body
Body' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"OversizeHandling")
      )

instance Prelude.Hashable Body where
  hashWithSalt :: Int -> Body -> Int
hashWithSalt Int
_salt Body' {Maybe OversizeHandling
oversizeHandling :: Maybe OversizeHandling
$sel:oversizeHandling:Body' :: Body -> Maybe OversizeHandling
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe OversizeHandling
oversizeHandling

instance Prelude.NFData Body where
  rnf :: Body -> ()
rnf Body' {Maybe OversizeHandling
oversizeHandling :: Maybe OversizeHandling
$sel:oversizeHandling:Body' :: Body -> Maybe OversizeHandling
..} = forall a. NFData a => a -> ()
Prelude.rnf Maybe OversizeHandling
oversizeHandling

instance Data.ToJSON Body where
  toJSON :: Body -> Value
toJSON Body' {Maybe OversizeHandling
oversizeHandling :: Maybe OversizeHandling
$sel:oversizeHandling:Body' :: Body -> Maybe OversizeHandling
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"OversizeHandling" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OversizeHandling
oversizeHandling
          ]
      )