graphql-engine/server/src-lib/Data/Parser/Expires.hs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

18 lines
532 B
Haskell
Raw Normal View History

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