ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Server.Conditional

Description

Conditional-GET and ETag handling, split by how the served body relates to upstream's. A pass-through body (an artifact) is upstream's bytes, so the client's validators are relayed upstream and an upstream 304 is passed back. A merged listing on the packument path takes our own ETag, derived from the serve's inputs rather than hashed over its output. It can be stale only in the safe direction (a spurious 200, never a wrong 304), and a 304 costs no assembly. RubyGems Compact Index replies and compact specifications hash their rendered identity bytes instead, so a 304 skips compression but still pays the fetch, merge or serialisation.

Synopsis

Our own ETag (transformed bodies)

data ETag Source #

An entity tag in the wire form the ETag header carries, kept apart from the bare digest.

Instances

Instances details
Show ETag Source # 
Instance details

Defined in Ecluse.Core.Server.Conditional

Methods

showsPrec :: Int -> ETag -> ShowS #

show :: ETag -> String #

showList :: [ETag] -> ShowS #

Eq ETag Source # 
Instance details

Defined in Ecluse.Core.Server.Conditional

Methods

(==) :: ETag -> ETag -> Bool #

(/=) :: ETag -> ETag -> Bool #

Ord ETag Source # 
Instance details

Defined in Ecluse.Core.Server.Conditional

Methods

compare :: ETag -> ETag -> Ordering #

(<) :: ETag -> ETag -> Bool #

(<=) :: ETag -> ETag -> Bool #

(>) :: ETag -> ETag -> Bool #

(>=) :: ETag -> ETag -> Bool #

max :: ETag -> ETag -> ETag #

min :: ETag -> ETag -> ETag #

mkStrongETag :: Digest SHA256 -> ETag Source #

Quote a SHA-256 fingerprint, hex-encoded, as a strong ETag: one exact byte representation.

mkWeakETag :: Digest SHA256 -> ETag Source #

A weak ETag over a fingerprint, for a representation whose exact bytes the codec may change.

renderETag :: ETag -> Text Source #

The ETags wire form, the quoted opaque tag as it goes into the header.

etagHeader :: ETag -> Header Source #

The ETag response header carrying this validator.

data Conditional Source #

Whether the client's validator already matches the transformed body we would serve.

Constructors

NotModified ETag

Unchanged from the client's validator: answer 304 with this ETag and no body.

Modified ETag

Changed, or no validator was sent: serve 200 with this ETag.

Instances

Instances details
Show Conditional Source # 
Instance details

Defined in Ecluse.Core.Server.Conditional

Eq Conditional Source # 
Instance details

Defined in Ecluse.Core.Server.Conditional

evaluateETag :: RequestHeaders -> ETag -> Conditional Source #

Compare weakly (RFC 9110) against our own ETag. A merge has no single timestamp, so If-Modified-Since is ignored.

Relaying validators (pass-through bodies)

forwardValidators :: RequestHeaders -> RequestHeaders Source #

The only two client headers relayed upstream for a pass-through body, so upstream can answer 304.

isNotModified :: Status -> Bool Source #

Whether a pass-through upstream response is a 304 to pass back, upstream's own validator having decided.