0

在我的 Groovy on Grails 应用程序中,我有一个拦截器,它会为所有同步响应的控制器触发。

我有一个通过返回 WebPromise 异步呈现响应的端点。我注意到 Interceptor 的 after 方法不会只为异步响应端点调用。

class FirstInterceptor {

    int order = HIGHEST_PRECEDENCE

    FirstInterceptor() {
        matchAll()
    }

    boolean before() {
        println "Before is called!"
        true
    }

    boolean after() {
        println "After is called!" // <-- this does not get called for async response
        true
    }
}
import grails.async.web.WebPromises

class MyController {

    // Interceptor's before method gets called,
    // but after method does not get called
    def testAsync() {
        return WebPromises.task {
            render "Test Async Response"
        }
    }
    
    // Interceptor's before and after method gets called
    def testSync() {
        render "Test Sync Response"
    }

}

请告知我如何让拦截器的 after 方法用于异步响应渲染。

4

0 回答 0