     ///
     var state = State()
 
-    //
-    // Lifecycle hook called on end()
-    //
-    private var onEndInvoked: LifecycleHandler = {}
-
-    //
-    // Current pre-write lifecycle handler
-    //
-    private var writtenDataFilter: WrittenDataFilter = {body in return body}
+    private var lifecycle = Lifecycle()
 
     ///
     /// Set of cookies to return with the response

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


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

