Я пытаюсь использовать перехватчики Grails для сопоставления конкретных uri с определенными методами HTTP. Однако аргумент метода метода match игнорируется, несмотря на то, что я обновил свою версию Grails с 3.1.1 до 3.1.16, где эта проблема должна быть исправлена.
Упрощенная версия моего кода будет:
@GrailsCompileStatic
class MyInterceptor {
int order = HIGHEST_PRECEDENCE
MyInterceptor () {
match(uri: '/api/domain/*', method: 'PUT')
match(uri: '/api/domain/*', method: 'DELETE')
match(uri: '/api/domain/*', method: 'POST')
}
}
Со следующим тестом перехватчика:
@TestFor(MyInterceptor)
class MyInterceptorSpec extends Specification {
@Unroll
def "it matches '#method #uri'"() {
when: "A request matches the interceptor"
withRequest(uri: uri, method: method)
then:"The interceptor does match"
interceptor.doesMatch()
where:
uri | method
'/api/domain/1' | 'PUT'
'/api/domain/1' | 'POST'
'/api/domain/1' | 'DELETE'
}
@Unroll
def "it does not match '#method #uri'"() {
when:
withRequest(uri: uri, method: method)
then:
!interceptor.doesMatch()
where:
uri | method
'/api/domain' | 'GET'
'/api/domain/1' | 'GET' // failing test
}
}
Как я могу гарантировать, что перехватчик соответствует uris только для заданных методов HTTP?