     ///
     /// - Parameter newPreFlush: The new pre-flush lifecycle handler
     public func setOnEndInvoked(_ newOnEndInvoked: LifecycleHandler) -> LifecycleHandler {
-        let oldOnEndInvoked = onEndInvoked
-        onEndInvoked = newOnEndInvoked
+        let oldOnEndInvoked = lifecycle.onEndInvoked
+        lifecycle.onEndInvoked = newOnEndInvoked
         return oldOnEndInvoked
     }
 

    ///
    /// - Parameter newWrittenDataFilter: The new written data filter
    public func setWrittenDataFilter(_ newWrittenDataFilter: WrittenDataFilter) -> WrittenDataFilter {
        let oldWrittenDataFilter = writtenDataFilter
        writtenDataFilter = newWrittenDataFilter
        return oldWrittenDataFilter
    }


        }

        if  let data = buffer.data {
            let content = lifecycle.writtenDataFilter(body: data)
            let contentLength = headers["Content-Length"]
            if  contentLength == nil {
                headers["Content-Length"] = String(content.length)
