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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, might we worth a prefix line custom client-server implementations: they have no specific handling in the browser.

- {{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.
Comment on lines +12 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. My concern here is that this has no specific browser integration. That might be worth spelling out (it is implied but not said). Words like "(browsers have no specific handling for these header: they are processed custom client code) or similar

Further, if this is used in a few protocols it might be worth listing a few, such as "Open Data (OData) protocol"

<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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The HTTP **`Preference-Applied`** header informs the client about which preferences from the `Prefer` request header were applied by the server.
The HTTP **`Preference-Applied`** header informs the client about which preferences from the {{httpheader("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
```
Comment on lines +41 to +53
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update the examples to show the request that caused this response (with appropriate words). You could do the same for prefer. The whole thing is a little abstract otherwise.


## Specifications

{{Specifications}}

## See also

- {{HTTPHeader("Prefer")}}