IfRange

View Source

Summary

The value of an If-Range HTTP header.

The If-Range header can contain either an entity tag (ETag) or an HTTP date.

MDN If-Range Reference

HTTP/1.1 Specification

Signature

class IfRange {
  constructor(init: string | Date): IfRange;

  // Properties
  value: string;

  // Methods
  matches(resource: {
    etag?: string | null;
    lastModified?: number | Date | null;
  }): boolean;
  toString(): string;
  from(value: string | Date | null): IfRange;
}

Constructor Params

init

Properties

value

Raw header value, either an entity tag or an HTTP date.

Methods

matches(resource: { etag?: string | null; lastModified?: number | Date | null }): boolean

Checks if the If-Range condition is satisfied for the current resource state.

This method always returns true if the If-Range header is not present, meaning the range request should proceed unconditionally.

The If-Range header can contain either:

  • An HTTP date (RFC 7231 IMF-fixdate format)
  • An entity tag (ETag)

When comparing ETags, only strong entity tags are matched as per RFC 7233. Weak entity tags (prefixed with W/) are never considered a match.

resource

The current resource state to compare against

toString(): string

Returns the string representation of the header value.

from(value: string | Date | null): IfRange

Parse an If-Range header value.

value

The header value (string, Date, or null)