{-# 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.XRay.Types.Http
-- 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.XRay.Types.Http 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

-- | Information about an HTTP request.
--
-- /See:/ 'newHttp' smart constructor.
data Http = Http'
  { -- | The IP address of the requestor.
    Http -> Maybe Text
clientIp :: Prelude.Maybe Prelude.Text,
    -- | The request method.
    Http -> Maybe Text
httpMethod :: Prelude.Maybe Prelude.Text,
    -- | The response status.
    Http -> Maybe Int
httpStatus :: Prelude.Maybe Prelude.Int,
    -- | The request URL.
    Http -> Maybe Text
httpURL :: Prelude.Maybe Prelude.Text,
    -- | The request\'s user agent string.
    Http -> Maybe Text
userAgent :: Prelude.Maybe Prelude.Text
  }
  deriving (Http -> Http -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Http -> Http -> Bool
$c/= :: Http -> Http -> Bool
== :: Http -> Http -> Bool
$c== :: Http -> Http -> Bool
Prelude.Eq, ReadPrec [Http]
ReadPrec Http
Int -> ReadS Http
ReadS [Http]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Http]
$creadListPrec :: ReadPrec [Http]
readPrec :: ReadPrec Http
$creadPrec :: ReadPrec Http
readList :: ReadS [Http]
$creadList :: ReadS [Http]
readsPrec :: Int -> ReadS Http
$creadsPrec :: Int -> ReadS Http
Prelude.Read, Int -> Http -> ShowS
[Http] -> ShowS
Http -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Http] -> ShowS
$cshowList :: [Http] -> ShowS
show :: Http -> String
$cshow :: Http -> String
showsPrec :: Int -> Http -> ShowS
$cshowsPrec :: Int -> Http -> ShowS
Prelude.Show, forall x. Rep Http x -> Http
forall x. Http -> Rep Http x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Http x -> Http
$cfrom :: forall x. Http -> Rep Http x
Prelude.Generic)

-- |
-- Create a value of 'Http' 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:
--
-- 'clientIp', 'http_clientIp' - The IP address of the requestor.
--
-- 'httpMethod', 'http_httpMethod' - The request method.
--
-- 'httpStatus', 'http_httpStatus' - The response status.
--
-- 'httpURL', 'http_httpURL' - The request URL.
--
-- 'userAgent', 'http_userAgent' - The request\'s user agent string.
newHttp ::
  Http
newHttp :: Http
newHttp =
  Http'
    { $sel:clientIp:Http' :: Maybe Text
clientIp = forall a. Maybe a
Prelude.Nothing,
      $sel:httpMethod:Http' :: Maybe Text
httpMethod = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:Http' :: Maybe Int
httpStatus = forall a. Maybe a
Prelude.Nothing,
      $sel:httpURL:Http' :: Maybe Text
httpURL = forall a. Maybe a
Prelude.Nothing,
      $sel:userAgent:Http' :: Maybe Text
userAgent = forall a. Maybe a
Prelude.Nothing
    }

-- | The IP address of the requestor.
http_clientIp :: Lens.Lens' Http (Prelude.Maybe Prelude.Text)
http_clientIp :: Lens' Http (Maybe Text)
http_clientIp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Http' {Maybe Text
clientIp :: Maybe Text
$sel:clientIp:Http' :: Http -> Maybe Text
clientIp} -> Maybe Text
clientIp) (\s :: Http
s@Http' {} Maybe Text
a -> Http
s {$sel:clientIp:Http' :: Maybe Text
clientIp = Maybe Text
a} :: Http)

-- | The request method.
http_httpMethod :: Lens.Lens' Http (Prelude.Maybe Prelude.Text)
http_httpMethod :: Lens' Http (Maybe Text)
http_httpMethod = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Http' {Maybe Text
httpMethod :: Maybe Text
$sel:httpMethod:Http' :: Http -> Maybe Text
httpMethod} -> Maybe Text
httpMethod) (\s :: Http
s@Http' {} Maybe Text
a -> Http
s {$sel:httpMethod:Http' :: Maybe Text
httpMethod = Maybe Text
a} :: Http)

-- | The response status.
http_httpStatus :: Lens.Lens' Http (Prelude.Maybe Prelude.Int)
http_httpStatus :: Lens' Http (Maybe Int)
http_httpStatus = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Http' {Maybe Int
httpStatus :: Maybe Int
$sel:httpStatus:Http' :: Http -> Maybe Int
httpStatus} -> Maybe Int
httpStatus) (\s :: Http
s@Http' {} Maybe Int
a -> Http
s {$sel:httpStatus:Http' :: Maybe Int
httpStatus = Maybe Int
a} :: Http)

-- | The request URL.
http_httpURL :: Lens.Lens' Http (Prelude.Maybe Prelude.Text)
http_httpURL :: Lens' Http (Maybe Text)
http_httpURL = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Http' {Maybe Text
httpURL :: Maybe Text
$sel:httpURL:Http' :: Http -> Maybe Text
httpURL} -> Maybe Text
httpURL) (\s :: Http
s@Http' {} Maybe Text
a -> Http
s {$sel:httpURL:Http' :: Maybe Text
httpURL = Maybe Text
a} :: Http)

-- | The request\'s user agent string.
http_userAgent :: Lens.Lens' Http (Prelude.Maybe Prelude.Text)
http_userAgent :: Lens' Http (Maybe Text)
http_userAgent = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Http' {Maybe Text
userAgent :: Maybe Text
$sel:userAgent:Http' :: Http -> Maybe Text
userAgent} -> Maybe Text
userAgent) (\s :: Http
s@Http' {} Maybe Text
a -> Http
s {$sel:userAgent:Http' :: Maybe Text
userAgent = Maybe Text
a} :: Http)

instance Data.FromJSON Http where
  parseJSON :: Value -> Parser Http
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Http"
      ( \Object
x ->
          Maybe Text
-> Maybe Text -> Maybe Int -> Maybe Text -> Maybe Text -> Http
Http'
            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
"ClientIp")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"HttpMethod")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"HttpStatus")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"HttpURL")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"UserAgent")
      )

instance Prelude.Hashable Http where
  hashWithSalt :: Int -> Http -> Int
hashWithSalt Int
_salt Http' {Maybe Int
Maybe Text
userAgent :: Maybe Text
httpURL :: Maybe Text
httpStatus :: Maybe Int
httpMethod :: Maybe Text
clientIp :: Maybe Text
$sel:userAgent:Http' :: Http -> Maybe Text
$sel:httpURL:Http' :: Http -> Maybe Text
$sel:httpStatus:Http' :: Http -> Maybe Int
$sel:httpMethod:Http' :: Http -> Maybe Text
$sel:clientIp:Http' :: Http -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
clientIp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
httpMethod
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Int
httpStatus
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
httpURL
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
userAgent

instance Prelude.NFData Http where
  rnf :: Http -> ()
rnf Http' {Maybe Int
Maybe Text
userAgent :: Maybe Text
httpURL :: Maybe Text
httpStatus :: Maybe Int
httpMethod :: Maybe Text
clientIp :: Maybe Text
$sel:userAgent:Http' :: Http -> Maybe Text
$sel:httpURL:Http' :: Http -> Maybe Text
$sel:httpStatus:Http' :: Http -> Maybe Int
$sel:httpMethod:Http' :: Http -> Maybe Text
$sel:clientIp:Http' :: Http -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
clientIp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
httpMethod
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
httpURL
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
userAgent