Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HttpServer an open class for customization #443

Merged
merged 2 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All notable changes to this project will be documented in this file. Changes not

## Changed

- Turn `HttpServer` and `HttpServerIO` into open classes to allow for more customization. ([#443](https://github.com/httpswift/swifter/pull/443)) by [@cobbal](https://github.com/cobbal)
- 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)
- 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)
- Update `SwifterTestsHttpParser` with a test for parsing bracketed query strings. ([#423](https://github.com/httpswift/swifter/pull/423)) by [@nejcvivod](https://github.com/nejcvivod)
Expand Down
2 changes: 1 addition & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ swiftlint.config_file = '.swiftlint.yml'
swiftlint.lint_files

# Warn when new tests are added but the XCTestManifests wasn't updated to run on Linux
tests_added_or_modified = git.modified_files.grep(/XCode\/Tests/).empty? || git.added_files.grep(/XCode\/Tests/).empty?
tests_added_or_modified = !git.modified_files.grep(/XCode\/Tests/).empty? || !git.added_files.grep(/XCode\/Tests/).empty?
xc_manifest_updated = !git.modified_files.grep(/XCode\/Tests\/XCTestManifests.swift/).empty?
if tests_added_or_modified && !xc_manifest_updated
warn("It seems like you've added new tests to the library. If that's the case, please update the [XCTestManifests.swift](https://github.com/httpswift/swifter/blob/stable/XCode/Tests/XCTestManifests.swift) file running in your terminal the command `swift test --generate-linuxmain`.")
Expand Down
4 changes: 2 additions & 2 deletions XCode/Sources/HttpServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public class HttpServer: HttpServerIO {
open class HttpServer: HttpServerIO {

public static let VERSION: String = {

Expand Down Expand Up @@ -56,7 +56,7 @@ public class HttpServer: HttpServerIO {

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

override public func dispatch(_ request: HttpRequest) -> ([String: String], (HttpRequest) -> HttpResponse) {
override open func dispatch(_ request: HttpRequest) -> ([String: String], (HttpRequest) -> HttpResponse) {
for layer in middleware {
if let response = layer(request) {
return ([:], { _ in response })
Expand Down
4 changes: 2 additions & 2 deletions XCode/Sources/HttpServerIO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public protocol HttpServerIODelegate: class {
func socketConnectionReceived(_ socket: Socket)
}

public class HttpServerIO {
open class HttpServerIO {

public weak var delegate: HttpServerIODelegate?

Expand Down Expand Up @@ -111,7 +111,7 @@ public class HttpServerIO {
self.state = .stopped
}

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

Expand Down