{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}

module Http.Exchange.Types
  ( HttpException (..)
  ) where

import Control.Exception qualified as E
import Data.Bytes (Bytes)

{- | Exceptions that occur when decoding an HTTP response.
If this happens, the only way to proceed is to
shut down the connection. Either the server does not
speak HTTP correct, or there is a mistake in this libary.
-}
data HttpException
  = ChunkTooLarge
  | ChunkedBodyEndOfInput
  | NonchunkedBodyEndOfInput
  | ContentLengthDuplicated
  | ContentLengthMalformed
  | ContentLengthTooLarge
  | ExpectedCrlfAfterChunk
  | ExpectedCrlfAfterChunkLength
  | ExpectedCrlfBeforeChunkLength
  | HeadersMalformed
  | -- | The entire contents of the response.
    HeadersEndOfInput
      {-# UNPACK #-} !Bytes
  | HeadersTooLarge
  | -- | If this one happens, there is a mistake in this
    -- library.
    ImplementationMistake
  | NonNumericChunkLength
  | PipelinedResponses
  | TransferEncodingUnrecognized
  | TransferEncodingDuplicated
  deriving anyclass (Show HttpException
Typeable HttpException
(Typeable HttpException, Show HttpException) =>
(HttpException -> SomeException)
-> (SomeException -> Maybe HttpException)
-> (HttpException -> String)
-> Exception HttpException
SomeException -> Maybe HttpException
HttpException -> String
HttpException -> SomeException
forall e.
(Typeable e, Show e) =>
(e -> SomeException)
-> (SomeException -> Maybe e) -> (e -> String) -> Exception e
$ctoException :: HttpException -> SomeException
toException :: HttpException -> SomeException
$cfromException :: SomeException -> Maybe HttpException
fromException :: SomeException -> Maybe HttpException
$cdisplayException :: HttpException -> String
displayException :: HttpException -> String
E.Exception)

instance Show HttpException where
  showsPrec :: Int -> HttpException -> ShowS
showsPrec Int
_ HttpException
ChunkTooLarge = String -> ShowS
showString String
"ChunkTooLarge"
  showsPrec Int
_ HttpException
ChunkedBodyEndOfInput = String -> ShowS
showString String
"ChunkedBodyEndOfInput"
  showsPrec Int
_ HttpException
NonchunkedBodyEndOfInput = String -> ShowS
showString String
"NonchunkedBodyEndOfInput"
  showsPrec Int
_ HttpException
ContentLengthDuplicated = String -> ShowS
showString String
"ContentLengthDuplicated"
  showsPrec Int
_ HttpException
ContentLengthMalformed = String -> ShowS
showString String
"ContentLengthMalformed"
  showsPrec Int
_ HttpException
ContentLengthTooLarge = String -> ShowS
showString String
"ContentLengthTooLarge"
  showsPrec Int
_ HttpException
ExpectedCrlfAfterChunk = String -> ShowS
showString String
"ExpectedCrlfAfterChunk"
  showsPrec Int
_ HttpException
ExpectedCrlfAfterChunkLength = String -> ShowS
showString String
"ExpectedCrlfAfterChunkLength"
  showsPrec Int
_ HttpException
ExpectedCrlfBeforeChunkLength = String -> ShowS
showString String
"ExpectedCrlfBeforeChunkLength"
  showsPrec Int
_ HttpException
HeadersMalformed = String -> ShowS
showString String
"HeadersMalformed"
  showsPrec Int
_ HeadersEndOfInput {} = String -> ShowS
showString String
"HeadersEndOfInput{..}"
  showsPrec Int
_ HttpException
HeadersTooLarge = String -> ShowS
showString String
"HeadersTooLarge"
  showsPrec Int
_ HttpException
ImplementationMistake = String -> ShowS
showString String
"ImplementationMistake"
  showsPrec Int
_ HttpException
NonNumericChunkLength = String -> ShowS
showString String
"NonNumericChunkLength"
  showsPrec Int
_ HttpException
PipelinedResponses = String -> ShowS
showString String
"PipelinedResponses"
  showsPrec Int
_ HttpException
TransferEncodingUnrecognized = String -> ShowS
showString String
"TransferEncodingUnrecognized"
  showsPrec Int
_ HttpException
TransferEncodingDuplicated = String -> ShowS
showString String
"TransferEncodingDuplicated"