Skip to content

Commit ca7a1ec

Browse files
authored
Merge pull request #450 from SoftwareEngineerChris/data-with-content-type
Adds Content-Type to Data HttpResponse
2 parents e9b1d5e + 9c9105d commit ca7a1ec

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

CHANGELOG.md

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

2323
- Add the `trailing_whitespace` rule in Swiftlint and autocorrect all the source files. ([#421](https://github.com/httpswift/swifter/pull/421)) by [@Vkt0r](https://github.com/Vkt0r)
2424
- Update the project for Xcode 11.1. ([#438](https://github.com/httpswift/swifter/pull/438)) by [@Vkt0r](https://github.com/Vkt0r)
25+
- Add optional 'Content-Type' to Data HttpResponse. ([#450](https://github.com/httpswift/swifter/pull/450)) by [@SoftwareEngineerChris](https://github.com/SoftwareEngineerChris)
2526

2627
## Changed
2728

XCode/Sources/HttpResponse.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public enum HttpResponseBody {
2626
case html(String)
2727
case htmlBody(String)
2828
case text(String)
29-
case data(Data)
29+
case data(Data, contentType: String? = nil)
3030
case custom(Any, (Any) throws -> String)
3131

3232
func content() -> (Int, ((HttpResponseBodyWriter) throws -> Void)?) {
@@ -56,7 +56,7 @@ public enum HttpResponseBody {
5656
return (data.count, {
5757
try $0.write(data)
5858
})
59-
case .data(let data):
59+
case .data(let data, _):
6060
return (data.count, {
6161
try $0.write(data)
6262
})
@@ -132,6 +132,7 @@ public enum HttpResponse {
132132
switch body {
133133
case .json: headers["Content-Type"] = "application/json"
134134
case .html: headers["Content-Type"] = "text/html"
135+
case .data(_, let contentType): headers["Content-Type"] = contentType
135136
default:break
136137
}
137138
case .movedPermanently(let location):

0 commit comments

Comments
 (0)