`isValidFieldName` validates a field name with `allSatisfy` over the
tchar set. `allSatisfy` returns `true` for an empty collection, so the
empty field name passes.
The file already states the rule it is implementing. The doc comment at
line 312 quotes:
```
token = 1*tchar
```
The derivation that follows is correct — I expanded `0x21, 0x23...0x27,
0x2a, 0x2b, 0x2d, 0x2e, 0x30...0x39, 0x5e...0x7a, 0x7c, 0x7e` byte by
byte against tchar minus `A-Z` and every one of the four rewriting steps
in lines 315-341 holds, including the `%x5E-60 / %x61-7A` → `%x5E-7A`
collapse. It is the `1*` quantifier that is missing: the code implements
`*tchar`.
### Scope
All three block types accept an empty name today, since they share
`HeaderFieldName.init`:
```
request: empty name -> accepted
response: empty name -> accepted
trailers: empty name -> accepted
```
An empty name serialises as `: value`, and RFC 9113 § 8.2.1 lists field
names as something a recipient is required to validate and treat as
malformed when the generic syntax is violated. This is a conformance gap
in a validator that already does the rest of that section — the
uppercase check, the CR/LF/NUL value check and the connection-specific
header check are all there.
(`":"` alone is already rejected, though as `unknownPseudoHeader` rather
than a name error, since `dropFirst()` leaves an empty base name that
matches no known pseudo-header. That path is unchanged here.)
### The change
An explicit early return, mirroring the shape swift-http-types uses for
the same production in `tokenValidity`:
```swift
if buffer.isEmpty {
return .invalid
}
```
### Tests
Added to `HTTP2FramePayloadToHTTP1CodecCRLFTests.swift`, which already
exercises `validateRequestBlock`, `validateResponseBlock` and
`validateTrailersBlock` directly for the § 8.2.1 value rules. Five
cases: the empty name in each of the three block types, plus `"a b"` and
an ordinary `x-custom-header` to keep the surrounding behaviour pinned.
### Verification
**I could not run `swift test` here**: this machine has Command Line
Tools without XCTest, so the test targets fail at `import XCTest` with
`no such module`. Pre-existing and unrelated — it reproduces on an
unmodified checkout (18 occurrences). **CI should be the authority;
treat my local run as unverified.**
`swift build` succeeds. I linked a throwaway executable against
`NIOHTTP2` to exercise the change directly:
```
PASS request: empty name -> rejected
PASS response: empty name -> rejected
PASS trailers: empty name -> rejected
PASS request: "a b" -> rejected
PASS request: "Host" (uppercase) -> rejected
PASS request: valid name -> accepted
PASS request: pseudo-headers only -> accepted
```
Before the change the first three were accepted.
### Conflicts
No open PR touches `HPACKHeaders+Validation.swift`. #531 and #562 touch
NIOHPACK, and #531 (`+ Fix a bug`) is about `isASCII` in
`HPACKHeader.swift` — no overlap with `isValidFieldName`.
SwiftNIO HTTP/2
This project contains HTTP/2 support for Swift projects using SwiftNIO. To get started, check the API docs.
Building
swift-nio-http2 is a SwiftPM project and can be built and tested very simply:
$ swift build
$ swift test
Versions
Just like the rest of the SwiftNIO family, swift-nio-http2 follows SemVer 2.0.0 with a separate document declaring SwiftNIO's Public API.
swift-nio-http2 1.x
swift-nio-http2 versions 1.x are a pure-Swift implementation of the HTTP/2 protocol for SwiftNIO. It's part of the SwiftNIO 2 family of repositories and does not have any dependencies besides swift-nio and Swift 5. As the latest version, it lives on the main branch.
To depend on swift-nio-http2, put the following in the dependencies of your Package.swift:
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.19.2"),
The minimum Swift version supported for SwiftNIO HTTP/2 releases are detailed below:
| SwiftNIO HTTP/2 | Minimum Swift Version |
|---|---|
1.0.0 ..< 1.18.0 |
5.0 |
1.18.0 ..< 1.21.0 |
5.2 |
1.21.0 ..< 1.23.0 |
5.4 |
1.24.0 ..< 1.27.0 |
5.5.2 |
1.27.0 ..< 1.29.0 |
5.6 |
1.29.0 ..< 1.31.0 |
5.7 |
1.31.0 ..< 1.37.0 |
5.8 |
1.37.0 ..< 1.39.0 |
5.9 |
1.39.0 ..< 1.43.0 |
6.0 |
1.43.0 ..< |
6.1 |
swift-nio-http2 0.x
The legacy swift-nio-http 0.x is part of the SwiftNIO 1 family of repositories and works on Swift 4.1 and newer but requires nghttp2 to be installed on your system. The source code can be found on the nghttp2-support-branch.
Developing SwiftNIO HTTP/2
For the most part, SwiftNIO development is as straightforward as any other SwiftPM project. With that said, we do have a few processes that are worth understanding before you contribute. For details, please see CONTRIBUTING.md in this repository.