Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(http): Add Prefer, Preferrence-Applied headers #37659

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions files/en-us/web/http/headers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ For more information, refer to the [CORS documentation](/en-US/docs/Web/HTTP/COR
- {{HTTPHeader("Content-Location")}}
- : Indicates an alternate location for the returned data.

## Preference

- {{HTTPHeader("Prefer")}}
- : Indicates preferences for specific server behaviors during request processing. For example, it can request minimal response content (`return=minimal`) or asynchronous processing (`respond-async`). The server processes the request normally if the header is unsupported.
- {{HTTPHeader("Preference-Applied")}}
- : Informs the client which preferences specified in the `Prefer` header were applied by the server. It is a response-only header providing transparency about preference handling.

## Proxies

- {{HTTPHeader("Forwarded")}}
Expand Down
74 changes: 74 additions & 0 deletions files/en-us/web/http/headers/prefer/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
title: Prefer
slug: Web/HTTP/Headers/Prefer
page-type: http-header
spec-urls: https://www.rfc-editor.org/rfc/rfc7240#section-2
---

{{HTTPSidebar}}

The HTTP **`Prefer`** header allows clients to indicate preferences for specific server behaviors during request processing.

> [!NOTE]
> The `Prefer` header is often used in custom client-server implementations. Ensure both client and server support this header before relying on it in production.
> The `Prefer` header does not cause the server to return an error if it does not support or apply the specified preferences. Instead, the server processes the request as if the header was not present.

<table class="properties">
<tbody>
<tr>
<th scope="row">Header type</th>
<td>
{{Glossary("Request header")}}
</td>
</tr>
<tr>
<th scope="row">{{Glossary("Forbidden header name")}}</th>
<td>No</td>
</tr>
</tbody>
</table>

## Syntax

```http
Prefer: <preference>
```

## Directives

- `respond-async`
- : Indicates that the client prefers asynchronous processing.
- `return=minimal`
- : Requests that the server return minimal content.
- `return=representation`
- : Requests a full resource representation in the response.
- `wait=<seconds>`
- : Suggests how long the server should wait for the request to complete before timing out.
- Custom preferences
- : Vendors or applications may define their own preferences to suit specific needs. For example, `custom-feature-enabled=true`.

## Examples

### Requesting minimal response

```http
GET /resource HTTP/1.1
Host: example.com
Prefer: return=minimal
```

### Requesting asynchronous processing

```http
POST /process HTTP/1.1
Host: example.com
Prefer: respond-async
```

## Specifications

{{Specifications}}

## See also

- {{HTTPHeader("Preference-Applied")}}
61 changes: 61 additions & 0 deletions files/en-us/web/http/headers/preference-applied/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: Preference-Applied
slug: Web/HTTP/Headers/Preference-Applied
page-type: http-header
spec-urls: https://www.rfc-editor.org/rfc/rfc7240#section-3
---

{{HTTPSidebar}}

The HTTP **`Preference-Applied`** header informs the client about which preferences from the `Prefer` request header were applied by the server.

<table class="properties">
<tbody>
<tr>
<th scope="row">Header type</th>
<td>
{{Glossary("Response header")}}
</td>
</tr>
<tr>
<th scope="row">{{Glossary("Forbidden header name")}}</th>
<td>No</td>
</tr>
<tr>
<th scope="row">
{{Glossary("CORS-safelisted response header")}}
</th>
<td>No</td>
</tr>
</tbody>
</table>

## Syntax

```http
Preference-Applied: <preference>
```

## Examples

### Server acknowledges a minimal response preference

```http
HTTP/1.1 200 OK
Preference-Applied: return=minimal
```

### Server acknowledges an asynchronous processing preference

```http
HTTP/1.1 202 Accepted
Preference-Applied: respond-async
```

## Specifications

{{Specifications}}

## See also

- {{HTTPHeader("Prefer")}}
Loading