From 6690f2bafe5a3202ddd55b1576fc389c603c7b65 Mon Sep 17 00:00:00 2001 From: Mike Tunnicliffe Date: Fri, 16 Mar 2018 15:16:47 +0000 Subject: [PATCH] Bridge KituraNet.HTTPStatusCode (#1217) --- .travis.yml | 1 + Sources/Kitura/HTTPStatusCode.swift | 25 + .../TestBridgingHTTPStatusCode.swift | 74 ++ docs/Classes.html | 8 +- docs/Classes/BodyParser.html | 8 +- docs/Classes/ContentType.html | 8 +- docs/Classes/Kitura.html | 8 +- docs/Classes/RouteRegex.html | 8 +- docs/Classes/Router.html | 8 +- docs/Classes/RouterMiddlewareGenerator.html | 8 +- docs/Classes/RouterRequest.html | 8 +- docs/Classes/RouterResponse.html | 16 +- docs/Classes/StaticFileServer.html | 8 +- .../StaticFileServer/CacheOptions.html | 8 +- docs/Classes/StaticFileServer/Options.html | 8 +- docs/Enums.html | 8 +- docs/Enums/JSONPError.html | 8 +- docs/Enums/LinkParameter.html | 8 +- docs/Enums/ParsedBody.html | 8 +- docs/Enums/RouterMethod.html | 8 +- docs/Protocols.html | 8 +- docs/Protocols/ResponseHeadersSetter.html | 8 +- docs/Protocols/RouterMiddleware.html | 8 +- docs/Structs.html | 40 +- docs/Structs/CodableHelpers.html | 742 ++++++++++++++++++ docs/Structs/HTTPVersion.html | 8 +- docs/Structs/Headers.html | 8 +- docs/Structs/Part.html | 8 +- docs/Structs/Part/HeaderType.html | 8 +- docs/Structs/SSLConfig.html | 8 +- docs/Typealiases.html | 41 +- .../Contents/Resources/Documents/Classes.html | 8 +- .../Documents/Classes/BodyParser.html | 8 +- .../Documents/Classes/ContentType.html | 8 +- .../Resources/Documents/Classes/Kitura.html | 8 +- .../Documents/Classes/RouteRegex.html | 8 +- .../Resources/Documents/Classes/Router.html | 8 +- .../Classes/RouterMiddlewareGenerator.html | 8 +- .../Documents/Classes/RouterRequest.html | 8 +- .../Documents/Classes/RouterResponse.html | 16 +- .../Documents/Classes/StaticFileServer.html | 8 +- .../StaticFileServer/CacheOptions.html | 8 +- .../Classes/StaticFileServer/Options.html | 8 +- .../Contents/Resources/Documents/Enums.html | 8 +- .../Resources/Documents/Enums/JSONPError.html | 8 +- .../Documents/Enums/LinkParameter.html | 8 +- .../Resources/Documents/Enums/ParsedBody.html | 8 +- .../Documents/Enums/RouterMethod.html | 8 +- .../Resources/Documents/Protocols.html | 8 +- .../Protocols/ResponseHeadersSetter.html | 8 +- .../Documents/Protocols/RouterMiddleware.html | 8 +- .../Contents/Resources/Documents/Structs.html | 40 +- .../Documents/Structs/CodableHelpers.html | 742 ++++++++++++++++++ .../Documents/Structs/HTTPVersion.html | 8 +- .../Resources/Documents/Structs/Headers.html | 8 +- .../Resources/Documents/Structs/Part.html | 8 +- .../Documents/Structs/Part/HeaderType.html | 8 +- .../Documents/Structs/SSLConfig.html | 8 +- .../Resources/Documents/Typealiases.html | 41 +- .../Contents/Resources/Documents/index.html | 10 +- .../Contents/Resources/Documents/search.json | 2 +- .../Contents/Resources/docSet.dsidx | Bin 94208 -> 98304 bytes docs/docsets/Kitura.tgz | Bin 134438 -> 142302 bytes docs/index.html | 10 +- docs/search.json | 2 +- docs/undocumented.json | 11 +- 66 files changed, 2127 insertions(+), 70 deletions(-) create mode 100644 Sources/Kitura/HTTPStatusCode.swift create mode 100644 Tests/KituraTests/TestBridgingHTTPStatusCode.swift create mode 100644 docs/Structs/CodableHelpers.html create mode 100644 docs/docsets/Kitura.docset/Contents/Resources/Documents/Structs/CodableHelpers.html diff --git a/.travis.yml b/.travis.yml index a0caa628a..47a02b07d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,7 @@ matrix: - os: osx osx_image: xcode9.2 sudo: required + env: JAZZY_ELIGIBLE=true - os: linux dist: trusty sudo: required diff --git a/Sources/Kitura/HTTPStatusCode.swift b/Sources/Kitura/HTTPStatusCode.swift new file mode 100644 index 000000000..455057b95 --- /dev/null +++ b/Sources/Kitura/HTTPStatusCode.swift @@ -0,0 +1,25 @@ +/* + * Copyright IBM Corporation 2018 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import KituraNet + +/// A dummy class to get the documentation for the HTTPStatusCode below to be emitted. +private class DummyHTTPStatusCodeClass {} + +/// Bridge [HTTPStatusCode](http://ibm-swift.github.io/Kitura-net/Enums/HTTPStatusCode.html) +/// from [KituraNet](http://ibm-swift.github.io/Kitura-net) so that you only need to import +/// `Kitura` to access it. +public typealias HTTPStatusCode = KituraNet.HTTPStatusCode diff --git a/Tests/KituraTests/TestBridgingHTTPStatusCode.swift b/Tests/KituraTests/TestBridgingHTTPStatusCode.swift new file mode 100644 index 000000000..0477d1ecc --- /dev/null +++ b/Tests/KituraTests/TestBridgingHTTPStatusCode.swift @@ -0,0 +1,74 @@ +/** + * Copyright IBM Corporation 2016, 2018 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +import XCTest +import Foundation + +@testable import Kitura + +#if os(Linux) +import Glibc +#else +import Darwin +#endif + +// This file does not import KituraNet and is relying on the typealias of +// HTTPStatusCode. This test is a simple response test to check that referring +// to HTTPStatusCode builds and runs without error. Other existing tests +// that import KituraNet should be sufficient to show that the typealias does not +// interfere in that case. +class TestBridgingHTTPStatusCode: KituraTest { + + static var allTests: [(String, (TestBridgingHTTPStatusCode) -> () throws -> Void)] { + return [ + ("testSimpleResponse", testSimpleResponse) + ] + } + + let router = TestBridgingHTTPStatusCode.setupRouter() + + func testSimpleResponse() { + performServerTest(router) { expectation in + self.performRequest("get", path:"/qwer", callback: {response in + XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil") + XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))") + XCTAssertNotNil(response?.headers["Date"], "There was No Date header in the response") + //XCTAssertEqual(response?.method, "GET", "The request wasn't recognized as a get") + do { + let body = try response?.readString() + XCTAssertEqual(body, "Received\n\n") + } catch { + XCTFail("Error reading body") + } + expectation.fulfill() + }) + } + } + + static func setupRouter() -> Router { + let router = Router() + router.get("/qwer") { _, response, next in + response.headers["Content-Type"] = "text/html; charset=utf-8" + do { + try response.send("Received\n\n").end() + } catch { + XCTFail("Error sending response. Error=\(error.localizedDescription)") + } + next() + } + return router + } +} diff --git a/docs/Classes.html b/docs/Classes.html index aa1c4a380..f6c26b919 100644 --- a/docs/Classes.html +++ b/docs/Classes.html @@ -118,6 +118,9 @@