开发者

Grails: Mapping to response codes, impossible to change http status code

开发者 https://www.devze.com 2022-12-24 00:17 出处:网络
\"404\" (controller: \'error\', action: \'pageNotFound\') Any changes to response.status inside the pageNotFound action is reverted back to 404 before the response is sent to the client. Is it possi
"404" (controller: 'error', action: 'pageNotFound')

Any changes to response.status inside the pageNotFound action is reverted back to 404 before the response is sent to the client. Is it possible to work around this开发者_JAVA技巧 some way? I would like to be able to change it to 410 when I detect that the resource has been deleted or 301 when it's moved permanently.


If that's not working try this in your error controller:

class ErrorController {

    def notFound = {
        redirect( action: 'gone')
      }

    def gone= {
        response.sendError(410, "Gone")
    }
}


Try setting the header yourself manually by response.setHeader()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号