Просмотр исходного кода

Adds new case htmlBody(String) to HttpResponse

Christian Steffens 7 лет назад
Родитель
Сommit
74532d92a9
2 измененных файлов с 10 добавлено и 2 удалено
  1. 3 1
      CHANGELOG.md
  2. 7 1
      XCode/Sources/HttpResponse.swift

+ 3 - 1
CHANGELOG.md

@@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. Changes not
 - A new `CHANGELOG.md` to keep track of changes in the project. ([#385](https://github.com/httpswift/swifter/pull/385)) by [@Vkt0r](https://github.com/Vkt0r)
 - Added [Danger](https://danger.systems/ruby/) and Swiftlint to the project. ([#398](https://github.com/httpswift/swifter/pull/398)) by [@Vkt0r](https://github.com/Vkt0r)
 - Added the following to `Scopes`: `manifest`, `ontouchstart`, `dataText`. ([#410](https://github.com/httpswift/swifter/pull/410)) by [@apocolipse](https://github.com/apocolipse)
+- Added `htmlBody(String)` to `HttpResonse`  as a compability case for the changed `html(String)` case.
 
 ## Fixed
 - An issue causing a crash regarding a thread race condition. ([#399](https://github.com/httpswift/swifter/pull/399)) by [@Vkt0r](https://github.com/Vkt0r)
@@ -37,7 +38,8 @@ All notable changes to this project will be documented in this file. Changes not
 - Refactor: Use Foundation API for Base64 encoding. ([#403](https://github.com/httpswift/swifter/pull/403)) by [@mazyod](https://github.com/mazyod)
 - Refactor: Use `URLComponents` for `HttpRequest` path and query parameters parsing [#404](https://github.com/httpswift/swifter/pull/404)) by [@mazyod](https://github.com/mazyod)
 - `HttpResponse` functions `statusCode()` and `reasonPhrase` changed to computed variables instead of functions, and made public (No impact on existing usage as it was previously internal). ([#410](https://github.com/httpswift/swifter/pull/410)) by [@apocolipse](https://github.com/apocolipse)
-
+- `HttpResponse`: `html` requires now a complete html-string, not only the body-part.
+- Include the `CHANGELOG.md` and `README.md` in the Xcode-Project for easy access / changes.
 
 ## Removed
 - Dropped macOS 10.9 support [#404](https://github.com/httpswift/swifter/pull/404)), [#408](https://github.com/httpswift/swifter/pull/408)) by [@mazyod](https://github.com/mazyod), [@Vkt0r](https://github.com/Vkt0r)

+ 7 - 1
XCode/Sources/HttpResponse.swift

@@ -24,6 +24,7 @@ public enum HttpResponseBody {
 
     case json(AnyObject)
     case html(String)
+    case htmlBody(String)
     case text(String)
     case data(Data)
     case custom(Any, (Any) throws -> String)
@@ -51,7 +52,12 @@ public enum HttpResponseBody {
                 return (data.count, {
                     try $0.write(data)
                 })
-            case .html(let body):
+            case .html(let html):
+                let data = [UInt8](html.utf8)
+                return (data.count, {
+                    try $0.write(data)
+                })
+            case .htmlBody(let body):
                 let serialised = "<html><meta charset=\"UTF-8\"><body>\(body)</body></html>"
                 let data = [UInt8](serialised.utf8)
                 return (data.count, {