2020-04-03 03:00:13 +03:00
|
|
|
module Data.Parser.Expires
|
2021-09-24 01:56:37 +03:00
|
|
|
( parseExpirationTime,
|
|
|
|
)
|
|
|
|
where
|
2020-04-03 03:00:13 +03:00
|
|
|
|
2021-09-24 01:56:37 +03:00
|
|
|
import Control.Monad.Except
|
|
|
|
import Data.Text.Conversions
|
|
|
|
import Data.Time.Clock
|
|
|
|
import Data.Time.Format (defaultTimeLocale, parseTimeM)
|
|
|
|
import Hasura.Prelude
|
2020-04-03 03:00:13 +03:00
|
|
|
|
|
|
|
-- | Extracts an absolute expiration time from a Expires header.
|
|
|
|
parseExpirationTime :: MonadError String m => Text -> m UTCTime
|
2021-09-24 01:56:37 +03:00
|
|
|
parseExpirationTime =
|
|
|
|
fromText
|
|
|
|
>>> parseTimeM True defaultTimeLocale "%a, %d %b %Y %T GMT"
|
|
|
|
>>> (`onNothing` throwError "Value of Expires header is not a valid timestamp")
|