Skip to content

Commit 398b81e

Browse files
author
Andrew Cobb
committed
Make HttpServer an open class for customization
Turn `HttpServer` into an open class to allow for slightly more customization than the `middleware` property allows. For my particular use case, I'm trying to add some simple logging, which would be an easy thing to do if I could just put a small wrapper around `dispatch`. I only made the `dispatch` method open here, since it seems like an obviously good customization point that would need inheritance instead of containment to customize.
1 parent 74d111d commit 398b81e

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file. Changes not
2525

2626
## Changed
2727

28+
- Turn `HttpServer` and `HttpServerIO` into open classes to allow for more customization. (#???) by [@cobbal](https://github.com/cobbal)
2829
- Set the version of the HTTP Server based in the project version in the **Info.plist** for macOS, iOS and tvOS platforms. ([#416](https://github.com/httpswift/swifter/pull/416)) by [@Vkt0r](https://github.com/Vkt0r)
2930
- Update `HttpParser` so it percent-encodes the URL components before initializing `URLComponents`. ([#423](https://github.com/httpswift/swifter/pull/423)) by [@nejcvivod](https://github.com/nejcvivod)
3031
- Update `SwifterTestsHttpParser` with a test for parsing bracketed query strings. ([#423](https://github.com/httpswift/swifter/pull/423)) by [@nejcvivod](https://github.com/nejcvivod)

XCode/Sources/HttpServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
public class HttpServer: HttpServerIO {
10+
open class HttpServer: HttpServerIO {
1111

1212
public static let VERSION: String = {
1313

@@ -56,7 +56,7 @@ public class HttpServer: HttpServerIO {
5656

5757
public var middleware = [(HttpRequest) -> HttpResponse?]()
5858

59-
override public func dispatch(_ request: HttpRequest) -> ([String: String], (HttpRequest) -> HttpResponse) {
59+
override open func dispatch(_ request: HttpRequest) -> ([String: String], (HttpRequest) -> HttpResponse) {
6060
for layer in middleware {
6161
if let response = layer(request) {
6262
return ([:], { _ in response })

XCode/Sources/HttpServerIO.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public protocol HttpServerIODelegate: class {
1212
func socketConnectionReceived(_ socket: Socket)
1313
}
1414

15-
public class HttpServerIO {
15+
open class HttpServerIO {
1616

1717
public weak var delegate: HttpServerIODelegate?
1818

@@ -111,7 +111,7 @@ public class HttpServerIO {
111111
self.state = .stopped
112112
}
113113

114-
public func dispatch(_ request: HttpRequest) -> ([String: String], (HttpRequest) -> HttpResponse) {
114+
open func dispatch(_ request: HttpRequest) -> ([String: String], (HttpRequest) -> HttpResponse) {
115115
return ([:], { _ in HttpResponse.notFound })
116116
}
117117

0 commit comments

Comments
 (0)