{-# 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.WAFRegional.Types.HTTPRequest
-- 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.WAFRegional.Types.HTTPRequest where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.WAFRegional.Types.HTTPHeader

-- | This is __AWS WAF Classic__ documentation. For more information, see
-- <https://docs.aws.amazon.com/waf/latest/developerguide/classic-waf-chapter.html AWS WAF Classic>
-- in the developer guide.
--
-- __For the latest version of AWS WAF__, use the AWS WAFV2 API and see the
-- <https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html AWS WAF Developer Guide>.
-- With the latest version, AWS WAF has a single set of endpoints for
-- regional and global use.
--
-- The response from a GetSampledRequests request includes an @HTTPRequest@
-- complex type that appears as @Request@ in the response syntax.
-- @HTTPRequest@ contains information about one of the web requests that
-- were returned by @GetSampledRequests@.
--
-- /See:/ 'newHTTPRequest' smart constructor.
data HTTPRequest = HTTPRequest'
  { -- | The HTTP version specified in the sampled web request, for example,
    -- @HTTP\/1.1@.
    HTTPRequest -> Maybe Text
hTTPVersion :: Prelude.Maybe Prelude.Text,
    -- | The two-letter country code for the country that the request originated
    -- from. For a current list of country codes, see the Wikipedia entry
    -- <https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2>.
    HTTPRequest -> Maybe Text
country :: Prelude.Maybe Prelude.Text,
    -- | The part of a web request that identifies the resource, for example,
    -- @\/images\/daily-ad.jpg@.
    HTTPRequest -> Maybe Text
uri :: Prelude.Maybe Prelude.Text,
    -- | A complex type that contains two values for each header in the sampled
    -- web request: the name of the header and the value of the header.
    HTTPRequest -> Maybe [HTTPHeader]
headers :: Prelude.Maybe [HTTPHeader],
    -- | The HTTP method specified in the sampled web request. CloudFront
    -- supports the following methods: @DELETE@, @GET@, @HEAD@, @OPTIONS@,
    -- @PATCH@, @POST@, and @PUT@.
    HTTPRequest -> Maybe Text
method :: Prelude.Maybe Prelude.Text,
    -- | The IP address that the request originated from. If the @WebACL@ is
    -- associated with a CloudFront distribution, this is the value of one of
    -- the following fields in CloudFront access logs:
    --
    -- -   @c-ip@, if the viewer did not use an HTTP proxy or a load balancer
    --     to send the request
    --
    -- -   @x-forwarded-for@, if the viewer did use an HTTP proxy or a load
    --     balancer to send the request
    HTTPRequest -> Maybe Text
clientIP :: Prelude.Maybe Prelude.Text
  }
  deriving (HTTPRequest -> HTTPRequest -> Bool
(HTTPRequest -> HTTPRequest -> Bool)
-> (HTTPRequest -> HTTPRequest -> Bool) -> Eq HTTPRequest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HTTPRequest -> HTTPRequest -> Bool
$c/= :: HTTPRequest -> HTTPRequest -> Bool
== :: HTTPRequest -> HTTPRequest -> Bool
$c== :: HTTPRequest -> HTTPRequest -> Bool
Prelude.Eq, ReadPrec [HTTPRequest]
ReadPrec HTTPRequest
Int -> ReadS HTTPRequest
ReadS [HTTPRequest]
(Int -> ReadS HTTPRequest)
-> ReadS [HTTPRequest]
-> ReadPrec HTTPRequest
-> ReadPrec [HTTPRequest]
-> Read HTTPRequest
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HTTPRequest]
$creadListPrec :: ReadPrec [HTTPRequest]
readPrec :: ReadPrec HTTPRequest
$creadPrec :: ReadPrec HTTPRequest
readList :: ReadS [HTTPRequest]
$creadList :: ReadS [HTTPRequest]
readsPrec :: Int -> ReadS HTTPRequest
$creadsPrec :: Int -> ReadS HTTPRequest
Prelude.Read, Int -> HTTPRequest -> ShowS
[HTTPRequest] -> ShowS
HTTPRequest -> String
(Int -> HTTPRequest -> ShowS)
-> (HTTPRequest -> String)
-> ([HTTPRequest] -> ShowS)
-> Show HTTPRequest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HTTPRequest] -> ShowS
$cshowList :: [HTTPRequest] -> ShowS
show :: HTTPRequest -> String
$cshow :: HTTPRequest -> String
showsPrec :: Int -> HTTPRequest -> ShowS
$cshowsPrec :: Int -> HTTPRequest -> ShowS
Prelude.Show, (forall x. HTTPRequest -> Rep HTTPRequest x)
-> (forall x. Rep HTTPRequest x -> HTTPRequest)
-> Generic HTTPRequest
forall x. Rep HTTPRequest x -> HTTPRequest
forall x. HTTPRequest -> Rep HTTPRequest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HTTPRequest x -> HTTPRequest
$cfrom :: forall x. HTTPRequest -> Rep HTTPRequest x
Prelude.Generic)

-- |
-- Create a value of 'HTTPRequest' 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:
--
-- 'hTTPVersion', 'hTTPRequest_hTTPVersion' - The HTTP version specified in the sampled web request, for example,
-- @HTTP\/1.1@.
--
-- 'country', 'hTTPRequest_country' - The two-letter country code for the country that the request originated
-- from. For a current list of country codes, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2>.
--
-- 'uri', 'hTTPRequest_uri' - The part of a web request that identifies the resource, for example,
-- @\/images\/daily-ad.jpg@.
--
-- 'headers', 'hTTPRequest_headers' - A complex type that contains two values for each header in the sampled
-- web request: the name of the header and the value of the header.
--
-- 'method', 'hTTPRequest_method' - The HTTP method specified in the sampled web request. CloudFront
-- supports the following methods: @DELETE@, @GET@, @HEAD@, @OPTIONS@,
-- @PATCH@, @POST@, and @PUT@.
--
-- 'clientIP', 'hTTPRequest_clientIP' - The IP address that the request originated from. If the @WebACL@ is
-- associated with a CloudFront distribution, this is the value of one of
-- the following fields in CloudFront access logs:
--
-- -   @c-ip@, if the viewer did not use an HTTP proxy or a load balancer
--     to send the request
--
-- -   @x-forwarded-for@, if the viewer did use an HTTP proxy or a load
--     balancer to send the request
newHTTPRequest ::
  HTTPRequest
newHTTPRequest :: HTTPRequest
newHTTPRequest =
  HTTPRequest' :: Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe [HTTPHeader]
-> Maybe Text
-> Maybe Text
-> HTTPRequest
HTTPRequest'
    { $sel:hTTPVersion:HTTPRequest' :: Maybe Text
hTTPVersion = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:country:HTTPRequest' :: Maybe Text
country = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:uri:HTTPRequest' :: Maybe Text
uri = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:headers:HTTPRequest' :: Maybe [HTTPHeader]
headers = Maybe [HTTPHeader]
forall a. Maybe a
Prelude.Nothing,
      $sel:method:HTTPRequest' :: Maybe Text
method = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:clientIP:HTTPRequest' :: Maybe Text
clientIP = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The HTTP version specified in the sampled web request, for example,
-- @HTTP\/1.1@.
hTTPRequest_hTTPVersion :: Lens.Lens' HTTPRequest (Prelude.Maybe Prelude.Text)
hTTPRequest_hTTPVersion :: (Maybe Text -> f (Maybe Text)) -> HTTPRequest -> f HTTPRequest
hTTPRequest_hTTPVersion = (HTTPRequest -> Maybe Text)
-> (HTTPRequest -> Maybe Text -> HTTPRequest)
-> Lens HTTPRequest HTTPRequest (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HTTPRequest' {Maybe Text
hTTPVersion :: Maybe Text
$sel:hTTPVersion:HTTPRequest' :: HTTPRequest -> Maybe Text
hTTPVersion} -> Maybe Text
hTTPVersion) (\s :: HTTPRequest
s@HTTPRequest' {} Maybe Text
a -> HTTPRequest
s {$sel:hTTPVersion:HTTPRequest' :: Maybe Text
hTTPVersion = Maybe Text
a} :: HTTPRequest)

-- | The two-letter country code for the country that the request originated
-- from. For a current list of country codes, see the Wikipedia entry
-- <https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 ISO 3166-1 alpha-2>.
hTTPRequest_country :: Lens.Lens' HTTPRequest (Prelude.Maybe Prelude.Text)
hTTPRequest_country :: (Maybe Text -> f (Maybe Text)) -> HTTPRequest -> f HTTPRequest
hTTPRequest_country = (HTTPRequest -> Maybe Text)
-> (HTTPRequest -> Maybe Text -> HTTPRequest)
-> Lens HTTPRequest HTTPRequest (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HTTPRequest' {Maybe Text
country :: Maybe Text
$sel:country:HTTPRequest' :: HTTPRequest -> Maybe Text
country} -> Maybe Text
country) (\s :: HTTPRequest
s@HTTPRequest' {} Maybe Text
a -> HTTPRequest
s {$sel:country:HTTPRequest' :: Maybe Text
country = Maybe Text
a} :: HTTPRequest)

-- | The part of a web request that identifies the resource, for example,
-- @\/images\/daily-ad.jpg@.
hTTPRequest_uri :: Lens.Lens' HTTPRequest (Prelude.Maybe Prelude.Text)
hTTPRequest_uri :: (Maybe Text -> f (Maybe Text)) -> HTTPRequest -> f HTTPRequest
hTTPRequest_uri = (HTTPRequest -> Maybe Text)
-> (HTTPRequest -> Maybe Text -> HTTPRequest)
-> Lens HTTPRequest HTTPRequest (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HTTPRequest' {Maybe Text
uri :: Maybe Text
$sel:uri:HTTPRequest' :: HTTPRequest -> Maybe Text
uri} -> Maybe Text
uri) (\s :: HTTPRequest
s@HTTPRequest' {} Maybe Text
a -> HTTPRequest
s {$sel:uri:HTTPRequest' :: Maybe Text
uri = Maybe Text
a} :: HTTPRequest)

-- | A complex type that contains two values for each header in the sampled
-- web request: the name of the header and the value of the header.
hTTPRequest_headers :: Lens.Lens' HTTPRequest (Prelude.Maybe [HTTPHeader])
hTTPRequest_headers :: (Maybe [HTTPHeader] -> f (Maybe [HTTPHeader]))
-> HTTPRequest -> f HTTPRequest
hTTPRequest_headers = (HTTPRequest -> Maybe [HTTPHeader])
-> (HTTPRequest -> Maybe [HTTPHeader] -> HTTPRequest)
-> Lens
     HTTPRequest HTTPRequest (Maybe [HTTPHeader]) (Maybe [HTTPHeader])
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HTTPRequest' {Maybe [HTTPHeader]
headers :: Maybe [HTTPHeader]
$sel:headers:HTTPRequest' :: HTTPRequest -> Maybe [HTTPHeader]
headers} -> Maybe [HTTPHeader]
headers) (\s :: HTTPRequest
s@HTTPRequest' {} Maybe [HTTPHeader]
a -> HTTPRequest
s {$sel:headers:HTTPRequest' :: Maybe [HTTPHeader]
headers = Maybe [HTTPHeader]
a} :: HTTPRequest) ((Maybe [HTTPHeader] -> f (Maybe [HTTPHeader]))
 -> HTTPRequest -> f HTTPRequest)
-> ((Maybe [HTTPHeader] -> f (Maybe [HTTPHeader]))
    -> Maybe [HTTPHeader] -> f (Maybe [HTTPHeader]))
-> (Maybe [HTTPHeader] -> f (Maybe [HTTPHeader]))
-> HTTPRequest
-> f HTTPRequest
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso [HTTPHeader] [HTTPHeader] [HTTPHeader] [HTTPHeader]
-> Iso
     (Maybe [HTTPHeader])
     (Maybe [HTTPHeader])
     (Maybe [HTTPHeader])
     (Maybe [HTTPHeader])
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 [HTTPHeader] [HTTPHeader] [HTTPHeader] [HTTPHeader]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The HTTP method specified in the sampled web request. CloudFront
-- supports the following methods: @DELETE@, @GET@, @HEAD@, @OPTIONS@,
-- @PATCH@, @POST@, and @PUT@.
hTTPRequest_method :: Lens.Lens' HTTPRequest (Prelude.Maybe Prelude.Text)
hTTPRequest_method :: (Maybe Text -> f (Maybe Text)) -> HTTPRequest -> f HTTPRequest
hTTPRequest_method = (HTTPRequest -> Maybe Text)
-> (HTTPRequest -> Maybe Text -> HTTPRequest)
-> Lens HTTPRequest HTTPRequest (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HTTPRequest' {Maybe Text
method :: Maybe Text
$sel:method:HTTPRequest' :: HTTPRequest -> Maybe Text
method} -> Maybe Text
method) (\s :: HTTPRequest
s@HTTPRequest' {} Maybe Text
a -> HTTPRequest
s {$sel:method:HTTPRequest' :: Maybe Text
method = Maybe Text
a} :: HTTPRequest)

-- | The IP address that the request originated from. If the @WebACL@ is
-- associated with a CloudFront distribution, this is the value of one of
-- the following fields in CloudFront access logs:
--
-- -   @c-ip@, if the viewer did not use an HTTP proxy or a load balancer
--     to send the request
--
-- -   @x-forwarded-for@, if the viewer did use an HTTP proxy or a load
--     balancer to send the request
hTTPRequest_clientIP :: Lens.Lens' HTTPRequest (Prelude.Maybe Prelude.Text)
hTTPRequest_clientIP :: (Maybe Text -> f (Maybe Text)) -> HTTPRequest -> f HTTPRequest
hTTPRequest_clientIP = (HTTPRequest -> Maybe Text)
-> (HTTPRequest -> Maybe Text -> HTTPRequest)
-> Lens HTTPRequest HTTPRequest (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HTTPRequest' {Maybe Text
clientIP :: Maybe Text
$sel:clientIP:HTTPRequest' :: HTTPRequest -> Maybe Text
clientIP} -> Maybe Text
clientIP) (\s :: HTTPRequest
s@HTTPRequest' {} Maybe Text
a -> HTTPRequest
s {$sel:clientIP:HTTPRequest' :: Maybe Text
clientIP = Maybe Text
a} :: HTTPRequest)

instance Core.FromJSON HTTPRequest where
  parseJSON :: Value -> Parser HTTPRequest
parseJSON =
    String
-> (Object -> Parser HTTPRequest) -> Value -> Parser HTTPRequest
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HTTPRequest"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe Text
-> Maybe [HTTPHeader]
-> Maybe Text
-> Maybe Text
-> HTTPRequest
HTTPRequest'
            (Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Maybe [HTTPHeader]
 -> Maybe Text
 -> Maybe Text
 -> HTTPRequest)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe Text
      -> Maybe [HTTPHeader]
      -> Maybe Text
      -> Maybe Text
      -> HTTPRequest)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"HTTPVersion")
            Parser
  (Maybe Text
   -> Maybe Text
   -> Maybe [HTTPHeader]
   -> Maybe Text
   -> Maybe Text
   -> HTTPRequest)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Maybe [HTTPHeader] -> Maybe Text -> Maybe Text -> HTTPRequest)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Country")
            Parser
  (Maybe Text
   -> Maybe [HTTPHeader] -> Maybe Text -> Maybe Text -> HTTPRequest)
-> Parser (Maybe Text)
-> Parser
     (Maybe [HTTPHeader] -> Maybe Text -> Maybe Text -> HTTPRequest)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"URI")
            Parser
  (Maybe [HTTPHeader] -> Maybe Text -> Maybe Text -> HTTPRequest)
-> Parser (Maybe [HTTPHeader])
-> Parser (Maybe Text -> Maybe Text -> HTTPRequest)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe (Maybe [HTTPHeader]))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Headers" Parser (Maybe (Maybe [HTTPHeader]))
-> Maybe [HTTPHeader] -> Parser (Maybe [HTTPHeader])
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe [HTTPHeader]
forall a. Monoid a => a
Prelude.mempty)
            Parser (Maybe Text -> Maybe Text -> HTTPRequest)
-> Parser (Maybe Text) -> Parser (Maybe Text -> HTTPRequest)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Method")
            Parser (Maybe Text -> HTTPRequest)
-> Parser (Maybe Text) -> Parser HTTPRequest
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"ClientIP")
      )

instance Prelude.Hashable HTTPRequest

instance Prelude.NFData HTTPRequest