Skip to content

Commit

Permalink
chore(HTTP): Some fixes for chunked encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
bsmth committed Dec 6, 2024
1 parent 91e9365 commit f20875e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion files/en-us/glossary/source_map/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ page-type: glossary-definition

{{GlossarySidebar}}

A **source map** is a file that maps transformed code back to a source, enabling the browser to reconstruct the original source code and show that reconstructed code in the debugger.
A **source map** is a file that maps between minified or transformed code received by the browser and its original unmodified form, allowing the original code to be reconstructed and used when debugging.

The JavaScript code executed by the browser has often been transformed in some way from the original source created by a developer.
For example, sources are often combined and minified to make delivering them from the server more efficient.
Expand Down
1 change: 0 additions & 1 deletion files/en-us/web/http/headers/no-vary-search/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,4 @@ No-Vary-Search: params, except=("id")

## See also

- [Speculation Rules API](/en-US/docs/Web/API/Speculation_Rules_API)
- [HTTP Caching: Vary](/en-US/docs/Web/HTTP/Caching#vary) and {{HTTPHeader("Vary")}} header
12 changes: 6 additions & 6 deletions files/en-us/web/http/headers/server-timing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ Server-Timing: db;dur=53, app;dur=47.2
- `<timing-metric>`
- : A comma-separated list of one or more metrics with the following components separated by semi-colons:
- `<name>`
- : A name component as a token (cannot contain spaces or special characters).
- : A name token (no spaces or special characters) for the metric that is implementation-specific or defined by the server, like `cacheHit`.
- `<duration>` {{optional_inline}}
- : A duration component consisting of the string `dur`, followed by `=`, followed by a value, like `dur=23.2`.
- : A duration as the string `dur`, followed by `=`, followed by a value, like `dur=23.2`.
- `<description>` {{optional_inline}}
- : A description component consisting of the string `desc`, followed by `=`, followed by a value as a token or a quoted string, like `desc=prod` or `desc="DB lookup"`.
- : A description as the string `desc`, followed by `=`, followed by a value as a token or a quoted string, like `desc=prod` or `desc="DB lookup"`.

The specification advises that names and descriptions should be kept as short as possible (use abbreviations and omit optional values where possible) to minimize the HTTP overhead.
Names and descriptions should be kept as short as possible (for example, use abbreviations and omit optional values) to minimize HTTP data overhead.

## Description

### Privacy and security

The `Server-Timing` header may expose potentially sensitive application and infrastructure information.
Consider to control which metrics are returned when and to whom on the server side.
For example, you could only show metrics to authenticated users and nothing to the public.
Decide which metrics to send, when to send them, and who should see them based on the use case.
For example, you may decide to only show metrics to authenticated users and nothing on public responses.

### PerformanceServerTiming interface

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/http/headers/set-cookie/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Set-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>; Secure; HttpOnl
This is the default behavior if the `SameSite` attribute is not specified.

> [!WARNING]
> Browser implementations vary when `SameSite` is omitted.
> Not all browsers set `SameSite=Lax` by default.
> See [Browser compatibility](#browser_compatibility) for details.
- `None`
Expand Down
4 changes: 2 additions & 2 deletions files/en-us/web/http/headers/sourcemap/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ browser-compat: http.headers.SourceMap

{{HTTPSidebar}}

The HTTP **`SourceMap`** {{Glossary("response header")}} links generated code to a {{Glossary("source map")}}, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger.
The HTTP **`SourceMap`** {{Glossary("response header")}} provides the location of a {{Glossary("source map")}} for the resource.

The HTTP `SourceMap` header has precedence over a source annotation (`sourceMappingURL=path-to-map.js.map`), and if both are present, the header URL is used to resolve the source map file.

Expand Down Expand Up @@ -50,7 +50,7 @@ SourceMap: /path/to/file.js.map
<optimized-javascript>
```

Developer tools use the mappings between optimized code and the original source to improve readability, which can make debugging easier.
Developer tools use the source map to reconstruct the original source from the optimized JavaScript returned in the response, allowing developers to debug the original code rather than the format that has been optimized for sending.

## Specifications

Expand Down
29 changes: 21 additions & 8 deletions files/en-us/web/http/headers/te/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ browser-compat: http.headers.TE
{{HTTPSidebar}}

The HTTP **`TE`** {{Glossary("request header")}} specifies the transfer encodings the user agent is willing to accept.
Some people informally consider "`Accept-Transfer-Encoding`" to be a more intuitive name for this header.
The transfer encodings are for message compression and chunking of data during transmission.

Note that `chunked` is always acceptable for HTTP/1.1 recipients and you don't have to specify `chunked` using the `TE` header.
However, it is useful if the client is accepting trailer fields in a chunked transfer coding using the `trailers` value.

See the {{HTTPHeader("Transfer-Encoding")}} response header for more details on transfer encodings.
Transfer encodings are applied at the protocol layer, so an application consuming responses receives the body as if no encoding was applied.

> [!NOTE]
> In [HTTP/2](https://httpwg.org/specs/rfc9113.html#ConnectionSpecific) and [HTTP/3](https://httpwg.org/specs/rfc9114.html#header-formatting), the `TE` header field is only accepted if the `trailers` value is set.
Expand All @@ -40,7 +37,7 @@ TE: gzip
TE: trailers
```

Multiple directives with {{glossary("quality values")}} as weights:
Multiple directives in a comma-separated list with {{glossary("quality values")}} as weights:

```http
TE: trailers, deflate;q=0.5
Expand All @@ -55,9 +52,24 @@ TE: trailers, deflate;q=0.5
- `gzip`
- : A format using the [Lempel-Ziv coding](https://en.wikipedia.org/wiki/LZ77_and_LZ78#LZ77) (LZ77), with a 32-bit CRC is accepted as a transfer coding name.
- `trailers`
- : Indicates that the client is willing to accept trailer fields in a chunked transfer coding.
- : Indicates that the client will not discard trailer fields in a [chunked transfer coding](/en-US/docs/Web/HTTP/Headers/Transfer-Encoding#chunked).
- `q`
- : When multiple transfer codings are acceptable, the `q` parameter ({{glossary("quality values")}}) syntax can order codings by preference.
- : When multiple transfer codings are acceptable, the `q` parameter ({{glossary("quality values")}}) syntax orders codings by preference.

Note that `chunked` is always supported by HTTP/1.1 recipients, so you don't need to specify it using the `TE` header.
See the {{HTTPHeader("Transfer-Encoding")}} header for more details.

## Examples

### Using the TE header with quality values

In the following request, the client indicates a preference for `gzip`-encoded responses with `deflate` as a second preference using a `q` value:

```http
GET /resource HTTP/1.1
Host: example.com
TE: gzip; q=1.0, deflate; q=0.8
```

## Specifications

Expand All @@ -70,5 +82,6 @@ TE: trailers, deflate;q=0.5
## See also

- {{HTTPHeader("Transfer-Encoding")}}
- {{HTTPHeader("Content-Encoding")}}
- {{HTTPHeader("Trailer")}}
- [Chunked transfer encoding](https://en.wikipedia.org/wiki/Chunked_transfer_encoding)
7 changes: 4 additions & 3 deletions files/en-us/web/http/headers/transfer-encoding/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ Transfer-Encoding: gzip, chunked
## Directives

- `chunked`
- : Data is sent in a series of chunks. The {{HTTPHeader("Content-Length")}} header is omitted in this case and at the beginning of each chunk you need to add the length of the current chunk in hexadecimal format, followed by `\r\n` and then the chunk itself, followed by another `\r\n`.
The terminating chunk is a regular chunk, with the exception that its length is zero.
It is followed by the trailer, which consists of a (possibly empty) sequence of header fields.
- : Data is sent in a series of chunks.
Content can be sent in streams of unknown size to be transferred as a sequence of length-delimited buffers, so the sender can keep a connection open, and let the recipient know when it has received the entire message.
The {{HTTPHeader("Content-Length")}} header must be omitted, and at the beginning of each chunk, a string of hex digits indicate the size of the chunk-data in octets, followed by `\r\n` and then the chunk itself, followed by another `\r\n`.
The terminating chunk is a zero-length chunk.
- `compress`
- : A format using the [Lempel-Ziv-Welch](https://en.wikipedia.org/wiki/LZW) (LZW) algorithm.
The value name was taken from the UNIX _compress_ program, which implemented this algorithm.
Expand Down

0 comments on commit f20875e

Please sign in to comment.