Commit Graph
73 Commits
Author SHA1 Message Date
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 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
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.
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
Guoye Zhang 45eb022491 Stop using Foundation on platforms with FoundationEssentials (#108)
Resolves #107
2025-10-21 08:44:07 -07:00
Guoye Zhang 3acdb1c8e8 Move HTTPRequest.url to the main library (#79)
Resolves #76
2025-10-17 07:51:03 +01: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
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
Guoye Zhang 51e4fd888f Remove usable from inline and internal properties 2024-11-13 13:27:04 +00:00
Guoye Zhang 32a95f29c1 Check the compiler version instead 2024-10-28 18:34:49 -07:00
Guoye Zhang c82e4078cd Adopt Mutex where available 2024-10-28 14:26:36 -07:00
Franz Busch 5eeef940dd Fix checks 2024-10-28 11:13:19 +01: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
Guoye Zhang 4ba4e72b06 Remove the public class 2024-10-23 12:21:05 -07:00
Guoye Zhang 6b3c3a26b7 Adopt NIOLock 2024-10-23 11:26:17 -07:00
Guoye Zhang 511d828079 Update CONTRIBUTORS 2024-07-16 17:10:23 -07: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 981c910492 Wrong error thrown when parsing trailer fields 2024-06-26 13:29:27 -07:00
Guoye Zhang b6db31de17 Remove mutating 2024-06-19 19:33:03 -07:00
Guoye Zhang 291e929d94 Add conveniences for modern HTTP parsers 2024-06-18 20:22:37 -07:00
Guoye Zhang 8f1ba42db6 Merge pull request #48 from guoye-zhang/lenient-legalize
Support lenient legalization of header field values
2024-05-13 10:30:36 -07:00
Guoye Zhang a584b11c3a Merge pull request #47 from guoye-zhang/connect-udp-bind
Connect-UDP-Listen to Connect-UDP-Bind
2024-05-13 10:16:45 -07:00
Guoye Zhang 7c0a607f38 Merge pull request #49 from simonjbeaumont/sb/musl-support
Support compiling against Musl
2024-05-09 02:20:16 -07:00
Si Beaumont 146ca95fbb Support compiling against Musl libc 2024-05-08 13:26:10 +01:00
Guoye Zhang c8357002a1 Update comment 2024-04-24 10:37:47 -07:00
Guoye Zhang 20d5ed91ae Support lenient legalization of header field values 2024-04-23 17:31:54 -07:00
Guoye Zhang 8fb12e8d82 Connect-UDP-Listen to Connect-UDP-Bind 2024-04-23 17:14:44 -07:00
Joannis Orlandos dfefea8004 Reserve capacity before appending elements during initialization through dictionary literal 2024-02-01 00:32:19 +01:00
Guoye Zhang be3407abef Add Connect-UDP-Listen 2024-01-16 14:08:48 -08:00
Max Desiatov a114507558 Fix building for WASI 2024-01-11 17:16:25 +00:00
Guoye Zhang fee4574296 Revert argument changes 2023-12-02 13:03:51 -08:00
Gwynne Raskind 28a5f3aaeb Per PR discussion, remove platform specifiers and discontinue use of some rather than forcing other packages to change their manifests. 2023-12-02 00:50:23 -06:00
Guoye Zhang 37e6ccad1c Fix format 2023-11-29 11:09:23 -08:00
Guoye Zhang 43c78a4f9d Improve the performance of setting and parsing status code 2023-11-28 18:32:11 -08:00
Guoye Zhang b4af788d7e Merge pull request #33 from guoye-zhang/fields-sequence
Eliminate the allocation of single element arrays
2023-11-16 23:34:38 -08:00
Guoye Zhang e716d5d2bc Values -> fields 2023-11-15 16:56:35 -08:00