dotnet / dotnet/aspnetcore

Add ResponseHeaderEncodingSelector on HttpSysOptions

Open
#66,162 0 comments 0 reactions 0 assignees View on GitHub
area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

When migrating from OWIN/Katana + HTTP.sys to ASP.NET Core + HTTP.sys, response headers containing non-ASCII characters are encoded differently.

**OWIN/Katana + HTTP.sys:** Response header values are encoded as Latin-1 (ISO-8859-1). A character like U+00A0 (non-breaking space) becomes a single byte `0xA0` on the wire.

**ASP.NET Core + HTTP.sys:** Response header values are encoded as UTF-8. The same U+00A0 becomes two bytes `0xC2 0xA0` on the wire, which clients interpret as two separate characters (`Â` + NBSP).

Kestrel provides `ResponseHeaderEncodingSelector` on `KestrelServerOptions` to control this. HTTP.sys only has `UseLatin1RequestHeaders` for **request** headers (added in .NET 5) — there is no equivalent for **response** headers.

### Describe the solution you'd like

Add a `UseLatin1ResponseHeaders` property (or a more general `ResponseHeaderEncoding` option) to `HttpSysOptions`, similar to:
- `HttpSysOptions.UseLatin1RequestHeaders` (existing, request-side only)
- `KestrelServerOptions.ResponseHeaderEncodingSelector` (Kestrel equivalent)

This would allow applications migrating from OWIN/Katana to ASP.NET Core HTTP.sys to maintain wire-level compatibility for response headers.

### Additional context

**Current state in .NET 8/9:**
- [HttpSysOptions.cs (.NET 8)](https://github.com/dotnet/aspnetcore/blob/v8.0.0/src/Servers/HttpSys/src/HttpSysOptions.cs) — only has `UseLatin1RequestHeaders`
- [HttpSysOptions.cs (.NET 9)](https://github.com/dotnet/aspnetcore/blob/v9.0.0/src/Servers/HttpSys/src/HttpSysOptions.cs) — same, no response encoding option added
- [KestrelServerOptions.ResponseHeaderEncodingSelector](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserveroptions.responseheaderencodingselector) — the Kestrel equivalent that already exists

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.