Middleware for HTTP Conditional Requests (RFC 7232).
It conditionally processes a HTTP request based on a precondition (such as an etag or modification date).
A precondition is specified using the
If-Unmodified-Since HTTP header.
Install with npm
> npm install express-preconditions --save
Include the following in your server startup
const preconditions =app
const preconditions =const options = ...app
See our test server for more details.
|error||A function that takes (
|requiredWith||An array of HTTP methods that must include one of the precondition headers. This prevents the lost update issue. Defaults to
|stateAsync||A function that takes
The resource state contains the
lastModified properties, which conform to the respective HTTP headers
and can be
stateAsync() obtains the resource state by sending a
HEAD request to the server.
The following HTTP status codes can be returned by the middleware
|304 (Not Modified)||The resource has not been modified since the version specified by the precondition(s).|
|412 (Precondition Failed)||A precondition failed.|
|428 (Precondition Required)||A precondition header is required to avoid the lost update issue.|
|501 (Not implemented)||A precondition is not yet implemented.|
If-Rangeheader is not currently supported.
The MIT license.
Copyright © 2016 Richard Schneider (firstname.lastname@example.org)