23 Commits
Author SHA1 Message Date
Fabian Fett bff4b6903c Regression fix: HTTPField.Name.init(parsed:) rejects uppercased names again (#155)
### Motivation

#144 introduced a regression in `HTTPField.Name(parsed:)`.

HTTP/2 and HTTP/3 require field names to be lowercased on the wire (RFC
9113 § 8.2.1, RFC 9114 § 4.1.2). Previously we enforced this by only
accepting lowercase ASCII letters.

In #144 we replaced a specific scan with `HTTPField.isValidToken`, which
is shared in multiple token validation places and returns `valid` for
uppercased names. We checked for `isValid`, which is true for `valid` as
well as `canonical` representations. Allowing `valid` and not just
`canonical` representations is the regression.

This lead to this unwanted behavior:
- `HTTPField.Name(parsed: "Content-Type")` now succeeds, so a decoder
can no longer detect the malformed message it has to reject.
- The returned name violates the documented invariant that
`canonicalName` is lowercased, so it compares and hashes unequal to
`HTTPField.Name("Content-Type")`, which does canonicalise.

This path had no test coverage, so neither regression was caught.

### Changes

Require `.canonical` rather than merely valid token validity in
`init(parsed:)`, restoring the pre-#144 behavior, and document why. Add
`HTTPFieldNameTests` covering both initializers: valid names, pseudo
header fields, invalid characters, the mixed-case canonicalisation that
`init(_:)` performs, and the uppercase rejection that `init(parsed:)`
performs.

### Result

`init(parsed:)` rejects uppercased names again and `canonicalName` is
lowercased for every name it returns.
2026-09-07 09:56:43 +02:00
Fabian Fett 46573d5db7 Make HTTPField.Name.init(parsed:) @inlinable (#154) 2026-09-04 11:27:11 +02:00
Fabian Fett 6aff14dae9 Add inlinables (#149)
### Motivation

We want to have fast code.

### Changes

Add `@inlinable` to a number of functions, to allow better compiler
optimizations.

### Result

Improvements in some benchmarks
2026-09-01 16:09:13 +02:00
Mathias Quintero c6bd833124 Improve Performance for HTTPField.Name Initializers (#144)
# Motivation

Currently when initializing a Field Name, we create a canonical
lowercased version of the field name. However, it is reasonable to
expect that a significant amount of the time the users will insert a
name string that is already lowercased, so turning it into lowercase
creates an extra unnecessary allocation

# Changes

This changes the validation step for the name to compute in a single
pass whether the name is valid and if it's already in the canonical
lowercased format. If it's already lowercased, then we can skip the
extra allocation and just reuse the same string. if it's valid but not
lowercased we can default to the previous logic.

For ultimate performance this iterates over Spans whenever we use Swift
6.4. For other Swift versions, we default to iterating over the UTF8View
instead, which is slightly slower, but keeps us backwards compatible.

# Result

More performance
2026-08-25 15:51:28 +02:00
Guoye Zhang 141600d7e6 Adopt availability macros (#127) 2026-06-22 15:16:29 -07:00
Guoye Zhang db774a277f Support embedded Swift (#116)
In order for swift-http-api-proposal to support embedded Swift,
swift-http-types has to support embedded Swift first.
2026-06-05 10:54:44 -07:00
shydevandGuoye Zhang b8fbf4109e Added known HTTP header field names from W3C Trace Context (#124)
these headers are defined by [W3C Trace
Context](https://www.w3.org/TR/trace-context/) and are used by
OpenTelemetry and other distributed tracing systems.

resolves #101.

Co-authored-by: Guoye Zhang <guoye_zhang@apple.com>
2026-06-01 19:08:54 +00:00
Xyan BhatnagarandGuoye Zhang bfafc0b613 Rename dictionaryId to dictionaryID (#120)
Matches swift naming convention

Co-authored-by: Guoye Zhang <guoye_zhang@apple.com>
2026-06-01 11:21:24 -07:00
Xyan Bhatnagar e9b43cc452 Added known HTTP header field names from RFC 9842 (#119) 2026-05-14 21:09:33 +00:00
Guoye Zhang 4bd2f8104f Eliminate hasPrefix usage for pseudo HTTP header names (#87)
UTF8 view is faster than hasPrefix

rdar://144395951
2025-02-15 18:14:25 -08:00
Guoye Zhang 51e4fd888f Remove usable from inline and internal properties 2024-11-13 13:27:04 +00:00
Franz Busch f3d9ec3eef [CI] Make all CI checks green
# Motivation

We just adopted GH actions and want to make sure all the CI checks are green.

# Modification

This PR makes the necessary changes to pass all checks. Including:

- Adding a licenseignore file
- Moving `swift-format` and adopting the config that we use in all other swift on server repos.

# Result

Green CI.
2024-10-24 22:30:18 +02:00
Eric Rosenberg 8fd0302d6e alphabetical 2024-07-03 14:11:19 -07:00
Eric Rosenberg 5ff044a1a4 Make RFC 9209 proxy-status public 2024-07-02 15:05:22 -07:00
Guoye Zhang 291e929d94 Add conveniences for modern HTTP parsers 2024-06-18 20:22:37 -07:00
Guoye Zhang 8fb12e8d82 Connect-UDP-Listen to Connect-UDP-Bind 2024-04-23 17:14:44 -07:00
Guoye Zhang be3407abef Add Connect-UDP-Listen 2024-01-16 14:08:48 -08:00
Guoye Zhang b45c5cf7c8 Complete built-in field names 2023-09-06 15:26:45 -07:00
Guoye Zhang e885fa315c Remove custom DecodingError and harden fields 2023-08-08 13:39:37 -07:00
Guoye Zhang 792abeab1f Support Codable 2023-08-07 18:09:53 -07:00
Guoye Zhang f610691a14 Code formatting fixes
Adding additional self. missed by SwiftFormat
2023-07-12 16:44:56 -07:00
Guoye Zhang ae848811f9 Internal API review feedback 2023-06-30 10:06:35 -07:00
Guoye Zhang c164739694 Import code 2023-06-30 10:06:35 -07:00