     }
 
     func encodeNil() throws {
-        encoder.data = nil
+        encoder.body = nil
     }
 
     func encode(_ value: Bool) throws {
-        encoder.data = value.description.data(using: .utf8)
+        if let data = value.description.data(using: .utf8) {
+            encoder.body = HTTPBody(data)
+        }
     }
 
     func encode(_ value: Int) throws {
-        encoder.data = value.description.data(using: .utf8)
+        if let data = value.description.data(using: .utf8) {
+            encoder.body = HTTPBody(data)
+        }
     }
 
     func encode(_ value: Double) throws {
-        encoder.data = value.description.data(using: .utf8)
+        if let data = value.description.data(using: .utf8) {
+            encoder.body = HTTPBody(data)
+        }
     }
 
     func encode(_ value: String) throws {
-        encoder.data = value.description.data(using: .utf8)
+        encoder.body = HTTPBody(string: value)
     }
 
     func encode(_ value: Int8) throws {

/// MARK: Content

extension DataEncoder: BodyEncoder {
    /// See BodyEncoder.encode
    public func encodeBody<T>(from encodable: T) throws -> HTTPBody where T: Encodable {
        let data = try encode(encodable)
        return HTTPBody(data)
    }
}

    }

    /// Encodes the object to data
    public func encode<E>(_ encodable: E) throws -> HTTPBody
        where E: Encodable
    {
        try encodable.encode(to: encoder)
        guard let body = encoder.body else {
            throw VaporError(identifier: "encoding-failed", reason: "An unknown error caused the data not to be encoded")
        }
        return body
    }
}

fileprivate final class _DataEncoder: Encoder {
    public var codingPath: [CodingKey]
    public var userInfo: [CodingUserInfoKey: Any]
    public var body: HTTPBody?

    public init() {
        self.codingPath = []
        self.userInfo = [:]
        self.body = nil
    }

    public func container<Key: CodingKey>(keyedBy type: Key.Type) -> KeyedEncodingContainer<Key> {
