【问题标题】:Grails change request.format?Grails 更改 request.format?
【发布时间】:2012-01-21 13:45:00
【问题描述】:
有没有办法在过滤器或控制器中修改request.format?
无论我尝试什么,我都会收到groovy.lang.GroovyRuntimeException: Cannot set read-only property: format。我需要以请求中立的方式管理我自己的内容类型协商,因此过滤器似乎是可行的方法。
【问题讨论】:
标签:
grails
groovy
mime-types
content-type
mime
【解决方案1】:
request.format 调用由RequestMimeTypesApi#getFormat method 处理。我没有对此进行测试,但认为以下内容适用于过滤器或控制器:
import org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes
....
request[GrailsApplicationAttributes.CONTENT_FORMAT] = format