Filters at Vapor4 Request?

Hello! Question, there is support for filters on PerfectHTTP... There is a code:
let confData = [
"servers": [
[
"name":"localhost",
"port": Int(http_port) ?? 8100,
"routes":[

[ "method":"post", "uri":"/admin/",
"handler": adminCommonHandler ],
[ "method":"get", "uri":"/**",
"handler": PerfectHTTPServer.HTTPHandler.staticFiles,
"documentRoot": webroot, "allowResponseFilters": true ]

],
"filters": [
[
"type":"request",
"priority":"high",
"name": MOCRequestFilter.filterHTTPRequest
],
]
]
]
]

the filter itself:
extension MOCRequestFilter: HTTPRequestFilter {

public func filter(request: HTTPRequest, response: HTTPResponse, callback: (HTTPRequestFilterResult) -> ()) {

let sessionMOC = GSManagedObjectContext(name: UUID().uuidString, concurrencyType: .privateQueueConcurrencyType)
sessionMOC.dbStoreCoordinator = pgDBC
request.scratchPad["sessionMOC"] = sessionMOC

callback(HTTPRequestFilterResult.continue(request, response))
}

/// Wrapper enabling PerfectHTTP 2.1 filter support
public static func filterHTTPRequest(data: [String:Any]) throws -> HTTPRequestFilter {
return MOCRequestFilter()
}
}

On Vapor4 how to rewrite it, please tell me?

Please edit your code so that it has proper indentation and is inside a code fence.

Terms of Service

Privacy Policy

Cookie Policy