Skip to content

Commit 9e8d032

Browse files
committed
Update proxy-server for swift 6
1 parent f953784 commit 9e8d032

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

proxy-server/Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// swift-tools-version:5.9
1+
// swift-tools-version:6.0
22
import PackageDescription
33

44
let package = Package(
55
name: "proxy-server",
66
platforms: [
7-
.macOS(.v14),
7+
.macOS(.v14)
88
],
99
dependencies: [
10-
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
10+
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.19.0"),
1111
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.4.0"),
1212
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.22.0"),
1313
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.6.0"),
@@ -25,7 +25,7 @@ let package = Package(
2525
// Enable better optimizations when building in Release configuration. Despite the use of
2626
// the `.unsafeFlags` construct required by SwiftPM, this flag is recommended for Release
2727
// builds. See <https://github.com/swift-server/guides#building-for-production> for details.
28-
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release)),
28+
.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
2929
]
3030
),
3131
.testTarget(

proxy-server/Sources/App/Middleware/ProxyServerMiddleware.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ struct ProxyServerMiddleware: RouterMiddleware {
6767
}
6868
}
6969
// extract length from content-length header
70-
let contentLength = if let header = request.headers[.contentLength], let value = Int(header) {
71-
HTTPClientRequest.Body.Length.known(value)
72-
} else {
73-
HTTPClientRequest.Body.Length.unknown
74-
}
70+
let contentLength =
71+
if let header = request.headers[.contentLength], let value = Int(header) {
72+
HTTPClientRequest.Body.Length.known(Int64(value))
73+
} else {
74+
HTTPClientRequest.Body.Length.unknown
75+
}
7576
clientRequest.body = .stream(
7677
request.body,
7778
length: contentLength

proxy-server/Tests/AppTests/AppTests.swift

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
@testable import App
21
import Hummingbird
32
import HummingbirdTesting
43
import ServiceLifecycle
5-
import XCTest
4+
import Testing
5+
6+
@testable import App
67

7-
final class AppTests: XCTestCase {
8+
struct AppTests {
89
struct TestAppArguments: AppArguments {
910
var hostname: String { "127.0.0.1" }
1011
var port: Int { 8081 }
@@ -55,66 +56,66 @@ final class AppTests: XCTestCase {
5556

5657
// MARK: tests
5758

58-
func testSimple() async throws {
59+
@Test func testSimple() async throws {
5960
try await self.testProxy { router in
6061
router.get("hello") { _, _ in
61-
return "Hello"
62+
"Hello"
6263
}
6364
} test: { port in
6465
let proxy = buildApplication(TestAppArguments(location: "", target: "http://localhost:\(port)"))
6566
try await proxy.test(.live) { client in
6667
try await client.execute(uri: "/hello", method: .get) { response in
67-
XCTAssertEqual(String(buffer: response.body), "Hello")
68+
#expect(String(buffer: response.body) == "Hello")
6869
}
6970
}
7071
}
7172
}
7273

73-
func testLocation() async throws {
74+
@Test func testLocation() async throws {
7475
try await self.testProxy { router in
7576
router.get("hello") { _, _ in
76-
return "Hello"
77+
"Hello"
7778
}
7879
} test: { port in
7980
let proxy = buildApplication(TestAppArguments(location: "/proxy", target: "http://localhost:\(port)"))
8081
try await proxy.test(.live) { client in
8182
try await client.execute(uri: "/proxy/hello", method: .get) { response in
82-
XCTAssertEqual(String(buffer: response.body), "Hello")
83+
#expect(String(buffer: response.body) == "Hello")
8384
}
8485
}
8586
}
8687
}
8788

88-
func testEchoBody() async throws {
89+
@Test func testEchoBody() async throws {
8990
let string = "This is a test body"
9091
let buffer = ByteBuffer(string: string)
9192
try await self.testProxy { router in
9293
router.post("echo") { request, _ in
9394
// test content length was passed through
94-
XCTAssertEqual(request.headers[.contentLength], buffer.readableBytes.description)
95+
#expect(request.headers[.contentLength] == buffer.readableBytes.description)
9596
return Response(status: .ok, body: .init(asyncSequence: request.body))
9697
}
9798
} test: { port in
9899
let proxy = buildApplication(TestAppArguments(location: "", target: "http://localhost:\(port)"))
99100
try await proxy.test(.live) { client in
100101
try await client.execute(uri: "/echo", method: .post, body: buffer) { response in
101-
XCTAssertEqual(response.body, buffer)
102+
#expect(response.body == buffer)
102103
}
103104
}
104105
}
105106
}
106107

107-
func testLargeBody() async throws {
108+
@Test func testLargeBody() async throws {
108109
try await self.testProxy { router in
109110
router.post("echo") { request, _ in
110-
return Response(status: .ok, body: .init(asyncSequence: request.body))
111+
Response(status: .ok, body: .init(asyncSequence: request.body))
111112
}
112113
} test: { port in
113114
let proxy = buildApplication(TestAppArguments(location: "", target: "http://localhost:\(port)"))
114115
try await proxy.test(.live) { client in
115116
let buffer = self.randomBuffer(size: 1024 * 1500)
116117
try await client.execute(uri: "/echo", method: .post, body: buffer) { response in
117-
XCTAssertEqual(response.body, buffer)
118+
#expect(response.body == buffer)
118119
}
119120
}
120121
}

0 commit comments

Comments
 (0)