Skip to content

Commit 6a24167

Browse files
committed
byterange: Add registry template, move syntax to description heading
1 parent 3f4ae41 commit 6a24167

File tree

1 file changed

+187
-50
lines changed

1 file changed

+187
-50
lines changed

draft-wright-http-patch-byterange.md

Lines changed: 187 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,26 @@ A byte range patch lists one or more _parts_. Each part specifies two essential
7878

7979
Each part MUST indicate a single contiguous range to be written to. Servers MUST reject byte range patches that don't contain a known range with a 422 or 400 error. (This would mean the client may be using a yet-undefined mechanism to specify the target range.)
8080

81-
The Content-Range field is used to specify the range to write to for each part:
81+
The simplest form to represent a byte range patch is the "message/byterange" media type, which is similar to an HTTP message:
8282

83-
The unsatisfied-range form (e.g. `bytes */1000`) is not meaningful, it MUST be treated as a syntax error.
83+
~~~http
84+
Content-Range: bytes 4-7/12
85+
86+
cdef
87+
~~~
88+
89+
This patch represents an instruction to write the four bytes "cdef" at an offset of 2 bytes. A document that used to list the numbers 0-9 on a line, would look like this after applying the patch:
90+
91+
~~~~
92+
01cdef6789␍␊
93+
~~~~
94+
95+
Although this example is a text document with a line terminator, patches are only carried as binary data, and can potentially carry or overwrite parts of multi-byte characters.
96+
97+
98+
## The Content-Range field
99+
100+
The Content-Range field (as seen inside a patch document) is used to specify the range to write to for each part:
84101

85102
The client MAY indicate the anticipated final size of the document by providing the complete-length form, for example `bytes 0-11/12`. This value does not affect the success of the write, however the server MAY use it for other purposes, especially for preallocating an optimal amount of space, and deciding when an upload in multiple parts has finished.
86103

@@ -92,13 +109,35 @@ As a special case, a Content-Range where the "last-pos" is omitted indicates tha
92109
Content-Range =/ range-unit SP first-pos "-/" ( complete-length / "*" )
93110
~~~
94111

95-
A "Content-Length" part field, if provided, describes the length of the part body.
112+
The unsatisfied-range form (e.g. `bytes */1000`) is not meaningful, it MUST be treated as a syntax error.
113+
114+
115+
## The Content-Length field
116+
117+
A "Content-Length" part field, if provided, describes the length of the part body. (To describe the size of the entire target resource, see the Content-Range field.)
118+
119+
If provided, it MUST exactly match the length of the range specified in the Content-Range field, and servers MUST error when the Content-Length mismatches the length of the range.
120+
96121

97-
Other "Content-" part fields in the patch document have the same meaning as if used in PUT request uploading the complete document (patch applied).
122+
## The Content-Type field
123+
124+
A "Content-Type" part field MUST have the same effect as if provided in a PUT request uploading the entire resource (patch applied).
125+
Its use is typically limited to providing the media type of new resources that don't exist.
126+
127+
128+
## Other fields
129+
130+
Other part fields in the patch document SHOULD have the same meaning as if provided in a PUT request uploading the entire resource (patch applied).
131+
132+
Use of such fields SHOULD be limited to cases where the meaning in the HTTP request headers would be different, where they would describe the entire patch, rather than the part. For example, the "Content-Type" field.
133+
134+
135+
136+
## Applying a patch
98137

99138
Servers SHOULD NOT accept requests that write beyond, and not adjacent to, the end of the resource. This would create a sparse file, where some bytes are undefined. For example, writing at byte 601 of a resource where bytes 0-599 are defined; this would leave byte 600 undefined. Servers that accept sparse writes MUST NOT disclose existing content, and SHOULD fill in undefined regions with zeros.
100139

101-
The expected length of the write can be computed from the part fields. If the actual length of the part body mismatches the expected length, this MUST be treated the same as a network interruption at the shorter length, but expecting the longer length. Recovering from this interruption may involve rolling back the entire request, or saving as many bytes as possible. The client can then recover the same way it would recover from a network error.
140+
The expected length of the write can be computed from the part fields. If the actual length of the part body mismatches the expected length, this MUST be treated the same as a network interruption at the shorter length, but anticipating the longer length. Recovering from this interruption may involve rolling back the entire request, or saving as many bytes as possible. The client can then recover the same way it would recover from a network error.
102141

103142

104143
## The multipart/byteranges media type
@@ -130,7 +169,7 @@ The syntax for multipart messages is defined in {{RFC2046, Section 5.1.1}}. Whil
130169
The multipart/byteranges type may be used for operations where multiple regions must be updated at the same time; clients may have an expectation that if there's an interruption, all of the parts will be rolled back.
131170

132171

133-
## The message/byterange media type
172+
## The message/byterange media type {#message-byterange}
134173

135174
When making a request with a single byte range, there is no need for a multipart boundary marker. This document defines a new media type "message/byterange" with the same semantics as a single byte range in a multipart/byteranges message, but with a simplified syntax.
136175

@@ -151,27 +190,58 @@ Content-Type: text/plain
151190

152191
This represents a request to modify a 600-byte document, overwriting 200 bytes of it, starting at a 100-byte offset.
153192

154-
The syntax is defined in {{messagebyterange-media-type}}.
155193

194+
### Syntax
156195

196+
The syntax re-uses concepts from the "multipart/byteranges" media type, except it omits the multipart separator, and so only allows a single range to be specified. It is also similar to the "message/http" media type, except the first line (the status line or request line) is omitted; a message/byterange document can be fed into a message/http parser by first prepending a line like "PATCH / HTTP/1.1".
157197

158-
## The message/byterange+bhttp media type
198+
It follows the syntax of HTTP message headers and body. It MUST include the Content-Range header field. If the message length is known by the sender, it SHOULD contain the Content-Length header field. Unknown or nonapplicable header fields MUST be ignored.
159199

160-
The "message/byterange+bhttp" has the same semantics as "message/byterange" but follows a binary format similar to "message/bhttp" {{RFC9292}}, and may be more suitable for some clients and servers, as all variable length strings are tagged with their length.
200+
The field-line and message-body productions are specified in [RFC9112].
201+
202+
~~~ abnf
203+
byterange-document = *( field-line CRLF )
204+
CRLF
205+
[ message-body ]
206+
~~~
161207

208+
This document has the same semantics as a single part in a "multipart/byteranges" document ({{Section 5.1.1 of RFC2046}}) or any response with a 206 (Partial Content) status code ({{Section 15.3.7 of RFC9110}}). A "message/byterange" document may be trivially transformed into a "multipart/byteranges" document by prepending a dash-boundary and CRLF, and appending a close-delimiter (a CRLF, dash-boundary, terminating "`--`", and optional CRLF).
162209

163-
## Overwriting
164210

165-
An overwrite only changes existing bytes, and so does not change the length of the document.
166211

167-
Overwriting operations MAY include a Content-Length field. If provided in overwriting operations, it MUST exactly match the length of the range specified in the Content-Range field. Servers MUST error when the Content-Length mismatches the length of the range.
168212

169213

170-
## Appending
214+
## The message/byterange+bhttp media type {#message-byterange-bhttp}
171215

172-
An append is when the range being replaced starts inside or at the end of the target document, and extends beyond the end, increasing the document length. For example, writing to bytes 10-19 of a 15 byte document, resulting in a 20 byte document.
216+
The "message/byterange+bhttp" has the same semantics as "message/byterange" but follows a binary format similar to "message/bhttp" {{RFC9292}}, and may be more suitable for some clients and servers, as all variable length strings are tagged with their length.
173217

174-
Aside from the fact the document size increases, it is the same as an overwrite.
218+
### Syntax
219+
220+
~~~
221+
Request {
222+
Framing Indicator (i) = 8,
223+
Known-Length Field Section (..),
224+
Known-Length Content (..),
225+
Padding (..),
226+
}
227+
228+
Known-Length Field Section {
229+
Length (i),
230+
Field Line (..) ...,
231+
}
232+
233+
Known-Length Content {
234+
Content Length (i),
235+
Content (..),
236+
}
237+
238+
Field Line {
239+
Name Length (i) = 1..,
240+
Name (..),
241+
Value Length (i),
242+
Value (..),
243+
}
244+
~~~
175245

176246

177247
## Range units
@@ -261,52 +331,119 @@ The server responds with 200 (OK). Since this completely writes out the 600-byte
261331

262332
# Registrations
263333

264-
## message/byterange media type
334+
## message/byterange
265335

266-
The "message/byterange" media type patches the defined byte range to some specified contents. It is similar to the "multipart/byteranges" media type, except it omits the multipart separator, and so only allows a single range to be specified.
336+
Type name:
337+
: message
267338

268-
It follows the syntax of HTTP message headers and body. It MUST include the Content-Range header field. If the message length is known by the sender, it SHOULD contain the Content-Length header field. Unknown or nonapplicable header fields MUST be ignored.
339+
Subtype name:
340+
: byterange
269341

270-
The field-line and message-body productions are specified in [RFC9112].
342+
Required parameters:
343+
: N/A
271344

272-
~~~ abnf
273-
byterange-document = *( field-line CRLF )
274-
CRLF
275-
[ message-body ]
276-
~~~
345+
Optional parameters:
346+
: N/A
277347

278-
This document has the same semantics as a single part in a "multipart/byteranges" document ({{Section 5.1.1 of RFC2046}}) or any response with a 206 (Partial Content) status code ({{Section 15.3.7 of RFC9110}}). A "message/byterange" document may be trivially transformed into a "multipart/byteranges" document by prepending a dash-boundary and CRLF, and appending a close-delimiter (a CRLF, dash-boundary, terminating "`--`", and optional CRLF).
348+
Encoding considerations:
349+
: binary
279350

351+
Security considerations:
352+
: See {{security-considerations}}
280353

281-
## message/byterange+bhttp media type
354+
Interoperability considerations:
355+
: See {{message-byterange}} of this document
282356

283-
The "message/byterange+bhttp" media type patches the defined byte range to some specified contents. It has the same semantics as "message/byterange", but follows a syntax closely resembling "message/bhttp" {{RFC9292}}
357+
Published specification:
358+
: This document
284359

285-
~~~
286-
Request {
287-
Framing Indicator (i) = 8,
288-
Known-Length Field Section (..),
289-
Known-Length Content (..),
290-
Padding (..),
291-
}
360+
Applications that use this media type:
361+
: HTTP applications that process filesystem-like writes to locations within a resource.
292362

293-
Known-Length Field Section {
294-
Length (i),
295-
Field Line (..) ...,
296-
}
363+
Fragment identifier considerations:
364+
: N/A
297365

298-
Known-Length Content {
299-
Content Length (i),
300-
Content (..),
301-
}
366+
Additional information:
367+
368+
: <dl spacing="compact">
369+
<dt>Deprecated alias names for this type:</dt><dd>N/A</dd>
370+
<dt>Magic number(s):</dt><dd>N/A</dd>
371+
<dt>File extension(s):</dt><dd>N/A</dd>
372+
<dt>Macintosh file type code(s):</dt><dd>N/A</dd>
373+
</dl>
374+
375+
Person and email address to contact for further information:
376+
: See Authors' Addresses section.
377+
378+
Intended usage:
379+
: COMMON
380+
381+
Restrictions on usage:
382+
: None.
383+
384+
Author:
385+
: See Authors' Addresses section.
386+
387+
Change controller:
388+
: IESG
389+
390+
391+
## message/byterange+bhttp
392+
393+
Type name:
394+
: message
395+
396+
Subtype name:
397+
: byterange+bhttp
398+
399+
Required parameters:
400+
: N/A
401+
402+
Optional parameters:
403+
: N/A
404+
405+
Encoding considerations:
406+
: binary
407+
408+
Security considerations:
409+
: See {{security-considerations}}
410+
411+
Interoperability considerations:
412+
: See {{message-byterange-bhttp}} of this document
413+
414+
Published specification:
415+
: This document
416+
417+
Applications that use this media type:
418+
: HTTP applications that process filesystem-like writes to locations within a resource.
419+
420+
Fragment identifier considerations:
421+
: N/A
422+
423+
Additional information:
424+
425+
: <dl spacing="compact">
426+
<dt>Deprecated alias names for this type:</dt><dd>N/A</dd>
427+
<dt>Magic number(s):</dt><dd>N/A</dd>
428+
<dt>File extension(s):</dt><dd>N/A</dd>
429+
<dt>Macintosh file type code(s):</dt><dd>N/A</dd>
430+
</dl>
431+
432+
Person and email address to contact for further information:
433+
: See Authors' Addresses section.
434+
435+
Intended usage:
436+
: COMMON
437+
438+
Restrictions on usage:
439+
: None.
440+
441+
Author:
442+
: See Authors' Addresses section.
443+
444+
Change controller:
445+
: IESG
302446

303-
Field Line {
304-
Name Length (i) = 1..,
305-
Name (..),
306-
Value Length (i),
307-
Value (..),
308-
}
309-
~~~
310447

311448
# Discussion
312449

@@ -350,7 +487,7 @@ One technique would be to use a 1xx interim response to indicate a location wher
350487
Operations more complicated than standard filesystem operations are out of scope for this media type. A feature of byte range patch is an upper limit on the complexity of applying the patch. In contrast, prepending, splicing, replace, or other complicated file operations could potentially require the entire file on disk be rewritten.
351488

352489

353-
# Security Considerations
490+
# Security Considerations {#security-considerations}
354491

355492
## Unallocated ranges
356493

0 commit comments

Comments
 (0)