Skip to content

Commit

Permalink
Add autoreleasePool for request handler
Browse files Browse the repository at this point in the history
  • Loading branch information
enums committed Jan 11, 2021
1 parent 124de64 commit 66bfe17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/Heze/App/HezeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public class HezeApp: HezeObject {
routes += pair.compactMap { (arg) in
let (method, handler) = arg
handler.bindContext(context)
return Route(method: method, uri: path, handler: handler.handleThenComplete)
return Route(method: method, uri: path, handler: handler.wrappedhandleThenComplete)
}
}
server.addRoutes(Routes(routes))
Expand Down
13 changes: 12 additions & 1 deletion Sources/Heze/View/HezeHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2019 Yuu Zheng. All rights reserved.
//

import Foundation
import PerfectHTTP

public typealias HezeMetaHandler = HezeHandler
Expand Down Expand Up @@ -50,7 +51,7 @@ open class HezeHandler: HezeObject {
return nil
}

internal func handleThenComplete(_ req: HTTPRequest, _ res: HTTPResponse) {
open func handleThenComplete(_ req: HTTPRequest, _ res: HTTPResponse) {
request = req
defer {
request = nil
Expand All @@ -65,4 +66,14 @@ open class HezeHandler: HezeObject {
}
}

open func wrappedhandleThenComplete(_ req: HTTPRequest, _ res: HTTPResponse) {
#if os(macOS)
autoreleasepool {
handleThenComplete(req, res)
}
#else
handleThenComplete(req, res)
#endif
}

}

0 comments on commit 66bfe17

Please sign in to comment.