Article Title
Article content...
Internet Engineering Task Force (IETF) J. Duncan
Internet-Draft Independent
Intended status: Standards Track July 17 2025
Expires: July 20, 2025
CSS Selector Range Unit for HTTP Range Requests
draft-duncan-selector-range-00
Abstract
This document defines a new range unit "selector" for use in HTTP
Range requests and responses. The selector range unit allows
clients to request specific portions of HTML and XML documents based
on CSS selectors, enabling fine-grained addressing of document
elements. This specification extends the byte-range mechanism
defined in RFC 7233 to support structured document manipulation.
Status of This Memo
This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering
Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet-
Drafts is at https://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months
and may be updated, replaced, or obsoleted by other documents at any
time. It is inappropriate to use Internet-Drafts as reference
material or to cite them other than as "work in progress."
This Internet-Draft will expire on July 20, 2025.
Copyright Notice
Copyright (c) 2025 IETF Trust and the persons identified as the
document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents
(https://trustee.ietf.org/license-info) in effect on the date of
publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must
Duncan Expires July 20, 2025 [Page 1]
Internet-Draft CSS Selector Range Unit July 2025
include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License.
Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1. Requirements Language . . . . . . . . . . . . . . . . . . 3
2. Selector Range Unit . . . . . . . . . . . . . . . . . . . . . 3
2.1. Syntax . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2. Semantics . . . . . . . . . . . . . . . . . . . . . . . . 4
3. Range Requests . . . . . . . . . . . . . . . . . . . . . . . 4
3.1. Request Examples . . . . . . . . . . . . . . . . . . . . 4
4. Range Responses . . . . . . . . . . . . . . . . . . . . . . . 5
4.1. 206 Partial Content . . . . . . . . . . . . . . . . . . . 5
4.2. 416 Range Not Satisfiable . . . . . . . . . . . . . . . . 5
4.3. Response Examples . . . . . . . . . . . . . . . . . . . . 6
5. Accept-Ranges Header Field . . . . . . . . . . . . . . . . . 6
6. Content-Range Header Field . . . . . . . . . . . . . . . . . 7
7. HTTP Method Semantics . . . . . . . . . . . . . . . . . . . . 7
7.1. GET and HEAD . . . . . . . . . . . . . . . . . . . . . . 7
7.2. PUT . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
7.3. DELETE . . . . . . . . . . . . . . . . . . . . . . . . . 8
7.4. POST . . . . . . . . . . . . . . . . . . . . . . . . . . 8
7.5. OPTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . 8
7.6. Conditional Requests . . . . . . . . . . . . . . . . . . . 9
7.7. Caching Considerations . . . . . . . . . . . . . . . . . . 9
8. Security Considerations . . . . . . . . . . . . . . . . . . . 9
8.1. Selector Injection . . . . . . . . . . . . . . . . . . . 8
8.2. Information Disclosure . . . . . . . . . . . . . . . . . 9
8.3. Resource Consumption . . . . . . . . . . . . . . . . . . 9
9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9
9.1. Range Unit Registration . . . . . . . . . . . . . . . . . 9
10. References . . . . . . . . . . . . . . . . . . . . . . . . . 10
10.1. Normative References . . . . . . . . . . . . . . . . . . 10
10.2. Informative References . . . . . . . . . . . . . . . . . 10
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 10
1. Introduction
HTTP Range requests, as defined in [RFC7233], allow clients to
request specific portions of resources. Currently, the primary range
unit is "bytes", which works well for binary resources but is less
suitable for structured documents like HTML or XML.
This specification introduces a "selector" range unit that uses CSS
selectors [SELECTORS-4] to identify specific elements within HTML and
XML documents. This enables:
o Fine-grained updates to specific document elements
o Bandwidth-efficient partial document transfers
o Element-level caching and validation
o Direct manipulation of DOM structures via HTTP
Duncan Expires July 20, 2025 [Page 2]
Internet-Draft CSS Selector Range Unit July 2025
The selector range unit is designed to work with existing HTTP
infrastructure while providing new capabilities for web applications
that treat HTML documents as both user interfaces and data
structures.
1.1. Requirements Language
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
"OPTIONAL" in this document are to be interpreted as described in
BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all
capitals, as shown here.
2. Selector Range Unit
The "selector" range unit identifies portions of HTML or XML
documents using CSS selectors. When used in a Range header field,
it specifies which elements within the document should be included
in the request or response.
2.1. Syntax
The syntax for selector range specifications uses the following ABNF
[RFC5234]:
selector-range-spec = selector-spec
selector-spec = "selector=" css-selector
css-selector = 1*( unreserved / pct-encoded / selector-chars )
selector-chars = ":" / "[" / "]" / "." / "#" / " " / ">" /
"+" / "~" / "*" / "," / "(" / ")" / "="
unreserved = ALPHA / DIGIT / "-" / "_"
pct-encoded = "%" HEXDIG HEXDIG
Examples of valid selector range specifications:
o selector=#header
o selector=.nav-menu
o selector=#content > p:first-child
o selector=[data-id="12345"]
o selector=#header p, #footer p
Note that certain characters in CSS selectors MUST be percent-encoded
when used in HTTP headers to avoid conflicts with HTTP syntax.
Duncan Expires July 20, 2025 [Page 3]
Internet-Draft CSS Selector Range Unit July 2025
2.2. Semantics
A selector range specification identifies zero or one element within
an HTML or XML document. The server processes the selector against
its representation of the resource and returns the first matching
element in document order.
This single-element design is fundamental to enabling RESTful
operations on document elements. By ensuring each selector identifies
at most one element, the specification allows HTTP methods like PUT
and DELETE to operate on specific, addressable resources within the
document. When multiple elements need to be addressed:
o Use CSS pseudo-classes like :nth-child(n) or :nth-of-type(n) to
select specific instances
o Select a container element that encloses multiple children (e.g.,
selector=ul to get all enclosed li elements)
o Use attribute selectors for unique identification (e.g.,
selector=[data-id="12345"])
Servers MUST use standard CSS selector matching rules as defined in
[SELECTORS-4]. If multiple elements match the selector, only the
first matching element in document order MUST be returned.
The selector is evaluated against the current state of the resource
at the time of the request. If the document structure changes
between requests, the same selector may match different elements.
Servers MUST follow the case sensitivity rules of the underlying
document format (case-insensitive for HTML element names, case-
sensitive for XML). Namespace handling in XML documents follows CSS
namespace selector syntax, though namespace declarations are outside
the scope of this specification. Response serialization SHOULD match
the original document's format.
3. Range Requests
A client requests a selector range by including a Range header field
with the selector range unit:
Range: selector=#content
Each Range header field MUST contain exactly one selector range
specification. Multiple selector range specifications within a
single Range header are not supported. This constraint ensures that
each request identifies a single element resource, enabling proper
RESTful semantics for HTTP methods like PUT and DELETE.
Note that CSS selectors themselves may contain comma-separated
selector groups (e.g., "#foo p, section p"), which are valid within
a single selector specification. When any selector (including those
with comma-separated groups) matches multiple elements in the
document, only the FIRST matching element in document order is
selected and returned. This single-element guarantee is essential
for maintaining idempotency in PUT operations and clear semantics
for DELETE operations.
Servers that support selector ranges MUST:
o Parse the selector from the Range header
o Evaluate the selector against the target resource
o Return the first matched element or an appropriate error response
3.1. Request Examples
Example 1: Request a specific element by ID
GET /index.html HTTP/1.1
Host: example.com
Range: selector=#main-article
Example 2: Request the first paragraph within a specific section
GET /index.html HTTP/1.1
Host: example.com
Range: selector=#content p
Duncan Expires July 20, 2025 [Page 4]
Internet-Draft CSS Selector Range Unit July 2025
Example 3: Request elements with specific attributes
GET /products.html HTTP/1.1
Host: example.com
Range: selector=[data-category="electronics"]
Example 4: Request using selector group (comma-separated selectors)
GET /index.html HTTP/1.1
Host: example.com
Range: selector=#header p, #footer p
Example 5: Request specific list item using nth-child
GET /menu.html HTTP/1.1
Host: example.com
Range: selector=#nav-menu li:nth-child(3)
Example 6: Request container element to get all children
GET /products.html HTTP/1.1
Host: example.com
Range: selector=ul.product-list
4. Range Responses
Servers that support selector ranges respond to valid range requests
with either a 206 (Partial Content) status code for successful
matches or a 416 (Range Not Satisfiable) status code when no
elements match the selector.
4.1. 206 Partial Content
When an element matches the selector, the server responds with a 206
status code and includes:
o The matched element in the response body
o A Content-Range header indicating which selector was satisfied
o A Content-Type header appropriate for the returned content
o A Vary: Range header to ensure proper cache handling
The response body contains the outerHTML representation of the first
matched element in document order.
Servers MUST include the Vary: Range header in all 206 responses for
selector ranges to prevent caches from serving partial content to
requests with different Range headers or no Range header.
4.2. 416 Range Not Satisfiable
When no elements match the provided selector, the server MUST respond
with a 416 status code. The response SHOULD include a Content-Range
header field with an unsatisfied-range value:
Content-Range: selector */
This indicates that the selector range unit is supported but the
specific selector matched no elements.
Duncan Expires July 20, 2025 [Page 5]
Internet-Draft CSS Selector Range Unit July 2025
4.3. Response Examples
Example 1: Successful selector match
HTTP/1.1 206 Partial Content
Content-Type: text/html; charset=utf-8
Content-Range: selector=#main-article
Vary: Range
Content-Length: 1234
Article content...Article Title
New comment text
First comment (only the first matching element returned)