164 Commits
Author SHA1 Message Date
Rick Newton-Rogers 4b64693c2d Bump swiftlang/github-workflows to 0.0.18 (#160)
The new workflows use macOS Golden Gate rather than macOS Tahoe by
default.
2026-11-17 00:43:56 +00:00
apple-ospo[bot] 379731fb1d Housekeeping: replace repo-level CODE_OF_CONDUCT (#156)
Replace repo-level CODE_OF_CONDUCT file with the inherited org-wide
[Code of
Conduct](https://github.com/apple/.github/blob/main/CODE_OF_CONDUCT.md)
in .github repo.

Co-authored-by: apple-ospo[bot] <326325757+apple-ospo[bot]@users.noreply.github.com>
2026-09-25 13:58:08 -07:00
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.
1.8.0
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 034320a9ff Add HTTP3 datagram error (#151) 2026-09-04 09:18:12 +02:00
Mathias Quintero 6c8ca82973 Improve allocations in Large Field Equality Checks (#150)
### Motivation

Checking for equality of multiple http fields creates an array per field
name. However, not every field will actually have multiple values, which
means we can save array allocations for fields that are only set once.

### Modifications

- Added an enum to handle single values without extra allocations

### Result

Faster equality checks.
1.7.0
2026-09-03 15:00:23 +00:00
Hashim Khan dfebed0b4e Make HTTPFields hashing consistent with equality (#143)
## Summary

HTTPFields equality does not depend on the order of differently named
fields. Hashing used storage order, so equal values could hash
differently.

This hashes each name group in relative order, then mixes those group
hashes without depending on name order. The existing hash test now
asserts equal hashes.

Fixes #139
2026-09-03 13:55:14 +00: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 QuinteroandFabian Fett f41c097554 Improve Performance of HTTPField.value (#146)
### Motivation

When instantiating new HTTPFields, the values need to be validated,
legalized and turned into the internal representation.
We use this representation to expose a string in `HTTPField.value` as
well as to iterate over raw bytes using
`HTTPField.withUnsafeBytesOfValue`.

Currently the internal representation is to use a ISO Latin 1 String to
store the bytes only once. This however means that we need to transcode
back and forth for non ascii values, which causes a lot of extra
computations and allocations.

### Modifications

1. Moved logic to a standalone structure for `HTTPField.Value` rather
than `ISOLatin1String`
2. Added Unit Tests and Benchmarks
3. Swapped internal storage of values to be an enum of either a string
or a value
4. Whenever the bytes stored are valid utf8, we will not always store
the value as a raw string. This means that we need the least amount of
allocations and transcoding when operating with the value through our
public API
5. We only store a raw array of bytes whenever the bytes are not valid
utf8. This speeds up `withUnsafeBytesOfValue` massively and
`HTTPField.value` a little bit
6. During legalization, store the modified bytes in a temporary buffer
instead of using lazy collections to avoid allocating an array and speed
up utf8 validation
7. Use spans whenever possible to speed up access to bytes without
boundary checks

### Result

These are the changes on the benchmarks added in this PR

```
HTTPField-asciiBytesValueRoundTrip
Instructions: 28K -> 6847 (-75%)
Malloc: 1 -> 1

HTTPField-asciiValueRoundTrip
Instructions: 7367 -> 3081 (-58%)
Malloc: 0 -> 0

HTTPField-invalidAsciiBytesValueRoundTrip
Instructions: 133K -> 7255 (-94%)
Malloc: 6 -> 1 (-83%)

HTTPField-invalidAsciiBytesValueRoundTripAsLenientValue
Instructions: 62K -> 6623 (-89%)
Malloc: 3 -> 1 (-66%)

HTTPField-invalidAsciiValueRoundTrip
Instructions: 93K -> 6959 (-92%)
Malloc: 5 -> 1 (-80%)

HTTPField-invalidNonASCIIValueRoundTrip
Instructions: 393K -> 8735 (-97%)
Malloc: 11 -> 1 (-91%)

HTTPField-nonASCIIValueRoundTrip
Instructions: 131K -> 3219 (-97%)
Malloc: 4 -> 0 (-100%)
```

---------

Co-authored-by: Fabian Fett <fabianfett@apple.com>
2026-08-31 11:30:56 +02:00
Eric RosenbergandFabian Fett 6226da4bb9 Add HTTP/2 and HTTP/3 error code types (#148)
### Motivation

HTTP/2 and HTTP/3 both carry a numeric error code to say why a stream or
a connection was terminated. HTTPTypes has no currency type for either,
so adopters passed bare integers around or defined their own.

### Modifications

Add HTTP2ErrorCode and HTTP3ErrorCode.

### Result

HTTP/2 and HTTP/3 error codes are first-class currency types.

---------

Co-authored-by: Fabian Fett <fabianfett@apple.com>
2026-08-29 00:04:31 +01:00
Mathias Quintero c12e12f7c5 Adding tests for HTTP Field Value Handling (#147)
### Motivation

In #146 we're going to be revamping the internal structure and
implementation of how we store values for http fields. To do it safely,
I want to add a few tests to make sure we do not regress it

### Modifications

Added tests for all the edge cases I could come up with for HTTP Field
Values

### Result

Tests Pass
2026-08-28 12:45:31 +00:00
Mathias QuinteroandFabian Fett af7e9d67a3 Improve Performance of HTTP Request and Response inits (#145)
### Motivation

Currently constructing a request or response from parsed http fields
requires multiple unnecessary allocations.
Mainly due to:
1. Allocations from resizing the array as we keep appending more values
to it
2. When running validation checks, we temporarily use an array of values
to represent the values for a given field name. When those fields are
set this requires an extra array allocation just to run the check

### Modifications

- Reserve needed capacity during initial of parsed fields to prevent
multiple subsequent allocations
- Avoid allocating an array while validating content length, content
disposition and location headers by validating them at insertion time
and therefore only iterating once

### Result

Reduction in allocations and instructions in benchmarks

Co-authored-by: Fabian Fett <fabianfett@apple.com>
2026-08-26 17:14:36 +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
Fabian Fett e186752bbc Improve equality check performance (#141)
### Motivation

#138 introduced code paths that scale quadratically when running an
equality check.

### Changes

- Introduce a new lock-step equality check that performs great for small
fields and fields that share roughly the same order
- Introduce a new lookup equality check that scales linear for vastly
different field orders

### Result

Faster equality checks
2026-08-18 14:46:30 +00:00
Fabian Fett 43cf84fb56 Reimplement HTTPFields on top of a simple Array (#138)
### Motivation

We like faster and simpler code. When optimizing performance we focus on
often used use-cases.

### Changes

- Reimplement HTTPFields on top of a simple Array

### Result

- HTTPFields building becomes significantly faster
- HTTPFields lookups are faster for small fields, and only slightly
slower for larger (nearly always offset by reduced build time)

Follow ups:

- Make the equality implementation smarter
2026-08-18 14:26:31 +02:00
Fabian Fett 4b1dd0cab3 Add hash tests, incl. a known failing one (#137)
### Motivation

The more we test the more we know about current behavior

### Changes

- Add tests for hashing, incl. a failing one

### Result

We know that our hash implementation isn't respecting different header
order
2026-08-14 12:56:29 +02:00
Fabian Fett e84a4ff0bc [Benchmark] Rewrite benchmarks to be scaling (#136)
### Motivation

As in #133 stated, we want to make performance improvements based on
numbers. However in #133 we only introduced benchmarks for
`HeaderFields` that are a fixed size long. This PR introduces scaling
benchmarks so that we can test `HeaderFields` with different lengths
(N=8, 16, 32, 64, 128)

### Changes

- Add scaling `HeaderFields` benchmarks
- Remove fixed size `HeaderFields` benchmarks

### Result

A clearer view into performance.
2026-08-14 11:17:11 +02:00
Fabian Fett 7d65507593 Move to swift-testing (#135)
### Motivation

We want to refactor some internals of this library. For this we need
tests. The existing tests are written with XCTest. Given that the total
number of test is relatively small, let's take the chance and move to
swift-testing before we add further tests.

### Changes

- Move all tests from XCTest to swift-testing
- This is a mechanical change

### Result

All tests use the test framework of the future.
2026-08-13 10:59:18 +02:00
Fabian Fett 37b3778072 Stop copying the name index dictionary on every HTTPFields.append (#134)
### Motivation

`_Storage.append(field:)` updated the name index through optional
chaining:

  self.index?[name, default: (first: location, last: 0)].last = location

The optional chaining self.index? is expanded into

  if var index = self.index {
index[name, default: (first: location, last: 0)].last = location // this
allocates – as dict is referenced by self.index and index
    self.index = index
  }

Because of this we have an allocation on every append.

### Changes

Nil-check `self.index` once, then mutate through the force-unwrapped
`self.index![name] = ...`, which is an addressable projection of the
stored property and mutates in place.

### Result

Allocations drop on every append-driven path.
2026-08-12 16:28:16 +02:00
Fabian Fett 8ec4cbcfa3 Add Benchmarks (#133)
### Motivation

We want to measurably improve performance.

### Changes

- Add a selection of use-cases that we can use to optimize our code
- Add thresholds for the newly added benchmarks so that we can ensure
that we don't regress in CI

### Result

A great baseline to start performance work.
2026-08-12 12:39:04 +00:00
Guoye Zhang 5b99e008ff Make QUERY method public (#130) 2026-06-22 15:33:26 -07: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.
1.6.0
2026-06-05 10:54:44 -07:00
Guoye Zhang 0fd14cc0fc Check that the decoded field value string is actually ISOLatin1 (#126)
The decoder assumes that the string is within the ISOLatin1 range
without checking, potentially allowing invalid values to be saved in an
HTTPField

rdar://178437865
2026-06-03 19:25:45 +01: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
Guoye Zhang f14fbc0e56 Add FoundationURL trait (#118)
Add a default enabled trait "FoundationURL" that can be disabled for
users who don't want Foundation dependencies. Also enable
`InternalImportsByDefault`.
2026-06-01 11:57:33 -07: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
Maxim V. Potapov abccd1b11f Add FreeBSD pthread support to NIOLock. (#123) 2026-05-22 14:49:38 -07:00
Xyan Bhatnagar e9b43cc452 Added known HTTP header field names from RFC 9842 (#119) 2026-05-14 21:09:33 +00:00
Rick Newton-RogersandGuoye Zhang c98018204b Drop Swift 6.0 (#114)
Motivation:

Swift 6.0 is no longer supported, we should bump the tools version and
remove it from our CI.

Modifications:

* Bump the Swift tools version to Swift 6.1
* Remove Swift 6.0 jobs where appropriate in main.yml, pull_request.yml

Result:

Code reflects our support window.

---------

Co-authored-by: Guoye Zhang <guoye_zhang@apple.com>
2026-04-01 21:51:13 +01:00
Rick Newton-Rogers 1eb908f88d Enable Swift 6.3 jobs in CI (#113)
Motivation:

Swift 6.3 has been released, we should add it to our CI coverage.

Modifications:

Add additional Swift 6.3 jobs where appropriate in main.yml,
pull_request.yml

Result:

Improved test coverage.
2026-04-01 13:55:25 +01:00
Iulian Onofrei fd0c5215e3 Remove soundness.sh script instructions from CONTRIBUTING.md (#110)
Removed instructions for running the soundness.sh script and adding it
as a git pre-push hook as the script does not exist anymore.
2025-11-24 10:24:28 +00:00
Guoye Zhang dae012b156 Bump tools version to 6.0 (#109)
Resolves rdar://163104978
2025-10-22 10:10:53 +01:00
Guoye Zhang 45eb022491 Stop using Foundation on platforms with FoundationEssentials (#108)
Resolves #107
1.5.1
2025-10-21 08:44:07 -07:00
Melissa Kilby 9410f6b9a3 chore: restrict GitHub workflow permissions - future-proof (#106)
See https://github.com/swiftlang/github-workflows/issues/167 for
additional context

This approach aligns with security best practices, as detailed in the
following documentation:

-
https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions
-
https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#defining-access-for-the-github_token-scopes
-
https://openssf.org/blog/2024/08/12/mitigating-attack-vectors-in-github-workflows/


The default GITHUB_TOKEN permissions are defined at the repository
level. This PR modifies the workflow-level overrides to conform to
OpenSSF best practices -> defense in depth.

Allow me to quote OpenSSF:

https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions

> The highest score is awarded when the permissions definitions in each
workflow's yaml file are set as read-only at the top level and the
required write permissions are declared at the run-level.”

> Remediation steps
> - Set top-level permissions as read-all or contents: read as described
in GitHub's documentation.
> - Set any required write permissions at the job-level. Only set the
permissions required for that job; do not set permissions: write-all at
the job level.


Compare to the LLVM project:

Top-level: contents read, e.g.
https://github.com/swiftlang/llvm-project/blob/next/.github/workflows/build-ci-container-windows.yml#L3-L4
-> this makes it future-proof

Job-level: Allow write permissions as needed, e.g.
https://github.com/swiftlang/llvm-project/blob/next/.github/workflows/build-ci-container-windows.yml#L53-L58

Signed-off-by: Melissa Kilby <mkilby@apple.com>
1.5.0
2025-10-17 17:50:38 -07:00
Guoye Zhang 3acdb1c8e8 Move HTTPRequest.url to the main library (#79)
Resolves #76
2025-10-17 07:51:03 +01:00
Guoye ZhangandCory Benfield 9c9d5ea7e3 Convert WebSocket URLRequest to RFC8441 HTTPRequest (#92)
WebSocket uses the extended-CONNECT form in HTTP/2 and HTTP/3. When
creating an HTTPRequest from a URLRequest, we should translate it into
the new form.

`:method`: `GET` -> `CONNECT`
`:scheme`: `wss`/`ws` -> `https`/`http`
`:protocol`: `websocket`

HTTPTypes defaults to modern HTTP versions, and the expectation is that
the HTTP/1 serializer has to translate the extended-CONNECT request back
to the old request form.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-10-05 11:13:17 -07:00
Rick Newton-Rogers 4366cd1e64 Enable Swift 6.2 jobs in CI (#105)
Motivation:

Swift 6.2 has been released, we should add it to our CI coverage.

Modifications:

Add additional Swift 6.2 jobs where appropriate in main.yml,
pull_request.yml

Result:

Improved test coverage.
2025-10-01 16:23:41 +01:00
Guoye Zhang 97c96755ae Add QUERY method (internal only) (#103) 2025-09-20 00:46:58 -07:00
Raphael b00139f252 Enable release mode builds (#102)
### Motivation:

Some errors do not show up in debug builds. Enabling release mode builds
improves the CI coverage.

### Modifications:

Enable release mode builds for pull requests and scheduled builds on
main.

### Result:

Improved CI coverage.
2025-07-30 08:50:56 +01:00
Rick Newton-RogersandGeorge Barnett 3faa71f2b7 Enable Swift 6.1 jobs in CI (#99)
Motivation:

Swift 6.1 has been released, we should add it to our CI coverage.

Modifications:

Add additional Swift 6.1 jobs where appropriate in main.yml,
pull_request.yml

Result:

Improved test coverage.

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-04-14 12:50:08 +01:00
Rick Newton-Rogers 4d7c10f344 add thresholds for Swift 6.1 from 6.0 thresholds (#100) 2025-04-14 12:16:08 +01:00
Rick Newton-Rogers a0a57e949a Enable macOS CI on pull requests (#97)
Motivation:

* Improve test coverage

Modifications:

Enable macOS CI to be run on pull request commits and make the use of
the nightly runner pool for main.yml jobs explicit.

Result:

Improved test coverage.
1.4.0
2025-04-01 07:23:38 -07:00
Rick Newton-Rogers 493e43a702 Enable macOS CI on merge to main and daily timer (#96)
Motivation:

* Improve test coverage
* Check test pass/fail status
* Monitor CI throughput

Modifications:

Enable macOS CI to be run on all merges to main and on a daily timer.

Result:

Improved test coverage run out-of-band at the moment so we can get a
feeling for if any changes need to be made in the repo or in the CI
pipelines to ensure timely and stable checks.
2025-03-28 14:53:30 +00:00
Rick Newton-Rogers 05dc8d9a36 Add static SDK CI workflow (#95)
Add static SDK CI workflow which runs on commits to PRs, merges to main
and daily on main.
2025-03-13 11:08:12 +00:00
Rick Newton-Rogers 66ab3c568c Only apply standard swift settings on valid targets (#93)
Only apply standard swift settings on valid targets. The current check
ignores plugins but that is not comprehensive enough.
2025-03-07 06:29:37 -08:00
Rick Newton-Rogers 5d11d38230 Rename nightly_6_1 params to nightly_next (#91)
Rename nightly_6_1 params to nightly_next; see
https://github.com/apple/swift-nio/pull/3122
2025-03-03 15:26:53 +00:00
Guoye Zhang e8011a7bc3 PseudoHeaderFields adopting CoW to reduce size (#88)
HTTPRequest size 288 -> 16
HTTPResponse size 80 -> 16

rdar://144520456
2025-02-21 17:30:57 -08: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
Rick Newton-Rogers 99d1c41bac CI use 6.1 nightlies (#85)
CI use 6.1 nightlies now that Swift development is happening in the 6.1
branch
2025-01-31 10:01:03 +00:00