Skip to content

Commit

Permalink
Reverted encode func signature change
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Jessup committed Sep 25, 2018
1 parent e5c4f92 commit 5ad1f4b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Sources/PerfectHTTP/HTTPResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#else
import Darwin
#endif

import PerfectLib
import Foundation

private let applicationJson = "application/json"
Expand Down Expand Up @@ -348,13 +350,23 @@ public extension HTTPResponse {
}
/// Encodes the Dictionary as a JSON string and converts that to a UTF-8 encoded [UInt8].
/// Adds the "application/json" content type unless `skipContentType` is true.
// @discardableResult
// func setBody(json: [String:Any], skipContentType: Bool = false) throws -> Self {
// let data = try JSONSerialization.data(withJSONObject: json)
// if !skipContentType {
// setHeader(.contentType, value: applicationJson)
// }
// return setBody(bytes: Array(data))
// }
/// Encodes the JSONConvertible as a JSON string and converts that to a UTF-8 encoded [UInt8].
/// Adds the "application/json" content type unless `skipContentType` is true.
@discardableResult
func setBody(json: [String:Any], skipContentType: Bool = false) throws -> Self {
let data = try JSONSerialization.data(withJSONObject: json)
func setBody(json: JSONConvertible, skipContentType: Bool = false) throws -> Self {
let string = try json.jsonEncodedString()
if !skipContentType {
setHeader(.contentType, value: applicationJson)
}
return setBody(bytes: Array(data))
return setBody(string: string)
}
/// Add a cookie to the outgoing response.
@discardableResult
Expand Down

0 comments on commit 5ad1f4b

Please sign in to comment.