Skip to content

Commit 896b4a4

Browse files
author
Christian Steffens
committed
Fixes tests using the new htmlBody response type
1 parent 74532d9 commit 896b4a4

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Tiny http server engine written in [Swift](https://developer.apple.com/swift/) p
1919
### How to start?
2020
```swift
2121
let server = HttpServer()
22-
server["/hello"] = { .ok(.html("You asked for \($0)")) }
22+
server["/hello"] = { .ok(.htmlBody("You asked for \($0)")) }
2323
server.start()
2424
```
2525

XCode/Sources/DemoServer.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
3030
}
3131
}
3232

33-
server["/magic"] = { .ok(.html("You asked for " + $0.path)) }
33+
server["/magic"] = { .ok(.htmlBody("You asked for " + $0.path)) }
3434

3535
server["/test/:param1/:param2"] = { request in
3636
scopes {
@@ -98,7 +98,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
9898
guard let name = multipart.name, let fileName = multipart.fileName else { continue }
9999
response += "Name: \(name) File name: \(fileName) Size: \(multipart.body.count)<br>"
100100
}
101-
return HttpResponse.ok(.html(response))
101+
return HttpResponse.ok(.htmlBody(response))
102102
}
103103

104104
server.GET["/login"] = scopes {
@@ -136,7 +136,7 @@ public func demoServer(_ publicDir: String) -> HttpServer {
136136

137137
server.POST["/login"] = { request in
138138
let formFields = request.parseUrlencodedForm()
139-
return HttpResponse.ok(.html(formFields.map({ "\($0.0) = \($0.1)" }).joined(separator: "<br>")))
139+
return HttpResponse.ok(.htmlBody(formFields.map({ "\($0.0) = \($0.1)" }).joined(separator: "<br>")))
140140
}
141141

142142
server["/demo"] = scopes {
@@ -165,11 +165,11 @@ public func demoServer(_ publicDir: String) -> HttpServer {
165165
server["/long"] = { _ in
166166
var longResponse = ""
167167
for index in 0..<1000 { longResponse += "(\(index)),->" }
168-
return .ok(.html(longResponse))
168+
return .ok(.htmlBody(longResponse))
169169
}
170170

171171
server["/wildcard/*/test/*/:param"] = { request in
172-
return .ok(.html(request.path))
172+
return .ok(.htmlBody(request.path))
173173
}
174174

175175
server["/stream"] = { _ in

XCode/SwifterSampleOSX/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Swifter
1010
do {
1111
let server = demoServer(try String.File.currentWorkingDirectory())
1212
server["/testAfterBaseRoute"] = { request in
13-
return .ok(.html("ok !"))
13+
return .ok(.htmlBody("ok !"))
1414
}
1515

1616
if #available(OSXApplicationExtension 10.10, *) {

XCode/Tests/ServerThreadingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ServerThreadingTests: XCTestCase {
3232
let queue = DispatchQueue(label: "com.swifter.threading")
3333
let hostURL: URL
3434

35-
server.GET[path] = { .ok(.html("You asked for " + $0.path)) }
35+
server.GET[path] = { .ok(.htmlBody("You asked for " + $0.path)) }
3636

3737
do {
3838

@@ -70,7 +70,7 @@ class ServerThreadingTests: XCTestCase {
7070
func testShouldHandleTheSameRequestConcurrently() {
7171

7272
let path = "/a/:b/c"
73-
server.GET[path] = { .ok(.html("You asked for " + $0.path)) }
73+
server.GET[path] = { .ok(.htmlBody("You asked for " + $0.path)) }
7474

7575
var requestExpectation: XCTestExpectation? = expectation(description: "Should handle the request concurrently")
7676

XCode/Tests/SwifterTestsHttpRouter.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SwifterTestsHttpRouter: XCTestCase {
2626
func testHttpRouterSlashRoot() {
2727

2828
router.register(nil, path: "/", handler: { _ in
29-
return .ok(.html("OK"))
29+
return .ok(.htmlBody("OK"))
3030
})
3131

3232
XCTAssertNotNil(router.route(nil, path: "/"))
@@ -35,7 +35,7 @@ class SwifterTestsHttpRouter: XCTestCase {
3535
func testHttpRouterSimplePathSegments() {
3636

3737
router.register(nil, path: "/a/b/c/d", handler: { _ in
38-
return .ok(.html("OK"))
38+
return .ok(.htmlBody("OK"))
3939
})
4040

4141
XCTAssertNil(router.route(nil, path: "/"))
@@ -48,7 +48,7 @@ class SwifterTestsHttpRouter: XCTestCase {
4848
func testHttpRouterSinglePathSegmentWildcard() {
4949

5050
router.register(nil, path: "/a/*/c/d", handler: { _ in
51-
return .ok(.html("OK"))
51+
return .ok(.htmlBody("OK"))
5252
})
5353

5454
XCTAssertNil(router.route(nil, path: "/"))
@@ -62,7 +62,7 @@ class SwifterTestsHttpRouter: XCTestCase {
6262
func testHttpRouterVariables() {
6363

6464
router.register(nil, path: "/a/:arg1/:arg2/b/c/d/:arg3", handler: { _ in
65-
return .ok(.html("OK"))
65+
return .ok(.htmlBody("OK"))
6666
})
6767

6868
XCTAssertNil(router.route(nil, path: "/"))
@@ -76,7 +76,7 @@ class SwifterTestsHttpRouter: XCTestCase {
7676
func testHttpRouterMultiplePathSegmentWildcards() {
7777

7878
router.register(nil, path: "/a/**/e/f/g", handler: { _ in
79-
return .ok(.html("OK"))
79+
return .ok(.htmlBody("OK"))
8080
})
8181

8282
XCTAssertNil(router.route(nil, path: "/"))
@@ -88,11 +88,11 @@ class SwifterTestsHttpRouter: XCTestCase {
8888
func testHttpRouterEmptyTail() {
8989

9090
router.register(nil, path: "/a/b/", handler: { _ in
91-
return .ok(.html("OK"))
91+
return .ok(.htmlBody("OK"))
9292
})
9393

9494
router.register(nil, path: "/a/b/:var", handler: { _ in
95-
return .ok(.html("OK"))
95+
return .ok(.htmlBody("OK"))
9696
})
9797

9898
XCTAssertNil(router.route(nil, path: "/"))
@@ -108,7 +108,7 @@ class SwifterTestsHttpRouter: XCTestCase {
108108
func testHttpRouterPercentEncodedPathSegments() {
109109

110110
router.register(nil, path: "/a/<>/^", handler: { _ in
111-
return .ok(.html("OK"))
111+
return .ok(.htmlBody("OK"))
112112
})
113113

114114
XCTAssertNil(router.route(nil, path: "/"))

0 commit comments

Comments
 (0)