Skip to content

Etag

HTTP entity tag values and metadata-based generator layers.

ETags are validators for a specific representation of a resource. Servers put them in ETag response headers so clients and intermediaries can revalidate cached content with If-None-Match, or protect writes with preconditions such as If-Match.

7 exports Added in v4.0.0 Source

Converting

toString

Added in v4.0.0 Source

Formats an Etag as an HTTP header value, including quotes and the W/ prefix for weak tags.

Signature

declare function toString(self: Etag): string;

Layers

layer

Added in v4.0.0 Source

Layer that provides a Generator which produces strong ETags from file size and modification time metadata.

When to use

Use when you need the Generator service to produce strong ETags and file size plus modification time reliably change for every byte-level change.

Gotchas

This layer marks metadata-derived tags as strong. If the underlying storage can update file contents without changing the recorded size or modification time, those tags can stop representing byte-for-byte identity.

See

  • layerWeak for weak metadata-derived ETags when byte-for-byte identity is not required
  • Generator for the service provided by this layer

Signature

declare const layer: Layer.Layer<Generator>;

layerWeak

Added in v4.0.0 Source

Layer that provides a Generator which produces weak ETags from file size and modification time metadata.

Signature

declare const layerWeak: Layer.Layer<Generator>;

Models

Etag type

Added in v4.0.0 Source

Represents an HTTP entity tag, either weak or strong.

Signature

type Etag = Weak | Strong;

Strong interface

Added in v4.0.0 Source

Strong HTTP entity tag.

Details

The value is the raw tag value without the surrounding quotes.

Signature

interface Strong {
  readonly _tag: "Strong";
  readonly value: string;
}

Weak interface

Added in v4.0.0 Source

Weak HTTP entity tag.

Details

The value is the raw tag value without the surrounding quotes or W/ prefix.

Signature

interface Weak {
  readonly _tag: "Weak";
  readonly value: string;
}

Services

Generator

Added in v4.0.0 Source

Service for generating ETags from filesystem file information or Web File-like metadata.

Signature

declare class Generator extends Shape<
  "effect/http/Etag/Generator",
  {
    readonly fromFileInfo: (info: Info) => Effect<Etag>;
    readonly fromFileWeb: (file: FileLike) => Effect<Etag>;
  },
  this
> {
  constructor(_: never);
}