Skip to content

Commit b2a633b

Browse files
authored
Close Connection on Failed Upgrade (#35)
### Goals ⚽ This PR works around an underlying SwiftNIO bug where HTTP decoding stops when detecting an HTTP upgrade but then isn't reenabled if that upgrade fails. For now we'll close instead of reusing the connection, but only for failed upgrades. This PR also updates dependencies and versions to 0.10.3.
1 parent cb4b089 commit b2a633b

File tree

5 files changed

+53
-20
lines changed

5 files changed

+53
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,4 @@ fastlane/test_output
8989

9090
iOSInjectionProject/
9191
.DS_Store
92+
.vscode

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ All notable changes to this project will be documented in this file.
88
- `0.x` Releases - [0.1.0](#010) | [0.2.0](#020) | [0.3.0](#030) | [0.4.0](#040) | [0.5.0](#050)
99
[0.6.0](#060) | [0.6.1](#061) | [0.7.0](#070) | [0.8.0](#080) | [0.8.1](#081)
1010
[0.8.2](#082) | [0.8.3](#083) | [0.9.0](#090) | [0.9.1](#091) | [0.10.0](#0100) | [0.10.1](#0101)
11-
[0.10.2](#0102)
11+
[0.10.2](#0102) | [0.10.3](#01003)
1212

1313
---
1414

15+
## [0.10.3](https://github.com/Alamofire/Firewalk/releases/tag/0.10.3)
16+
17+
Released on 2023-11-07.
18+
19+
#### Fixed
20+
21+
- Stall when failing an HTTP upgrade.
22+
- Fixed by [Jon Shier](https://github.com/jshier) in PR [#34](https://github.com/Alamofire/Firewalk/pull/34).
23+
1524
## [0.10.2](https://github.com/Alamofire/Firewalk/releases/tag/0.10.2)
1625

1726
Released on 2023-10-10.

Package.resolved

Lines changed: 25 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ swiftSettings = []
3535
let package = Package(name: "Firewalk",
3636
platforms: [.macOS(.v10_15)],
3737
products: [.executable(name: "firewalk", targets: ["firewalk"])],
38-
dependencies: [.package(url: "https://github.com/vapor/vapor.git", from: "4.79.0")],
38+
dependencies: [.package(url: "https://github.com/vapor/vapor.git", from: "4.86.0")],
3939
targets: [.executableTarget(name: "firewalk",
4040
dependencies: [.product(name: "Vapor", package: "vapor")],
4141
path: "Sources",

Sources/Methods.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,23 @@ func createMethodRoutes(for app: Application) throws {
5555
response.headers.replaceOrAdd(name: .location, value: redirectAddress)
5656
return response
5757
case 400..<600:
58-
return Response(status: .init(statusCode: code))
58+
let response = Response(status: .init(statusCode: code))
59+
// NIO stops parsing HTTP when an upgrade is detected, so close the connection.
60+
// Remove if NIO / Vapor fixes the issue.
61+
if request.headers.contains(name: .upgrade) {
62+
response.headers.connection = .close
63+
}
64+
65+
return response
5966
default:
60-
return Response(status: .badRequest)
67+
let response = Response(status: .badRequest)
68+
// NIO stops parsing HTTP when an upgrade is detected, so close the connection.
69+
// Remove if NIO / Vapor fixes the issue.
70+
if request.headers.contains(name: .upgrade) {
71+
response.headers.connection = .close
72+
}
73+
74+
return response
6175
}
6276
}
6377

0 commit comments

Comments
 (0)