java 如何在 HttpServletRequest 中添加 http 协议头值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6328302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you add a http protocol header value in HttpServletRequest ?
提问by Diablo.Wu
How do you add a http protocol header value in HttpServletRequest at a Filter,before call request.getHeader()
and get the header value?
如何在一个Filter的HttpServletRequest中添加http协议头值,调用之前request.getHeader()
获取头值?
回答by Adeel Ansari
You can find the hooks in HttpServletRequestWrapper.
您可以在HttpServletRequestWrapper 中找到钩子。
[Edited to include a link to an example]
[编辑以包含指向示例的链接]
Here you can find a fine example.
在这里你可以找到一个很好的例子。
回答by Drona
HttpServletRequest objects are read-only. You cannot modify them. But you can definitely extend their functionality by employing a decorator pattern and add mutability in the extended class. Take a look at the following post:
HttpServletRequest 对象是只读的。您不能修改它们。但是您绝对可以通过使用装饰器模式并在扩展类中添加可变性来扩展它们的功能。看看下面的帖子:
http://wilddiary.com/adding-custom-headers-java-httpservletrequest/
http://wilddiary.com/adding-custom-headers-java-httpservletrequest/