In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how zuul filters the header returned by downstream services in Springcloud. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
The version of Springcloud is Greenwich.SR2,Springboot and the version is 2.1.6.release.
The requirement is that Zuul does not want to return downstream services to return some header fields to the front end. As shown in List-1 below, this ZuulFilter is executed before SendResponseFilter, filterType is of type POST, and the important thing is that the value of zuulResponseHeaders in RequestContext is reset in run (). As shown in List-1, zuul will not return the header of xxx.
List-1
Public class ResponseHeaderFilter extends ZuulFilter {private static final String XXX = "xxx"; @ Override public String filterType () {return FilterConstants.POST_TYPE;} @ Override public int filterOrder () {/ / to execute return FilterConstants.SEND_RESPONSE_FILTER_ORDER-10;} @ Override public boolean shouldFilter () {return true before SendResponseFilter } @ Override public Object run () throws ZuulException {RequestContext context = RequestContext.getCurrentContext (); List filteredResponseHeaders = new ArrayList (); List zuulResponseHeaders = context.getZuulResponseHeaders () If (zuulResponseHeaders! = null) {for (Pair it: zuulResponseHeaders) {if (! it.first (). Contains (XXX)) {Pair pair = new Pair (it.first (), it.second ()); filteredResponseHeaders.add (pair) } context.put ("zuulResponseHeaders", filteredResponseHeaders); return null;}}
The difficulty is that in JSR's Servlet specification, resposne has only addHeader and setHeader, but no removeHeader, and setHeader is not an overlay, but an append, which is related to its underlying implementation. Take a look at Zuul's github issue and see this: https://github.com/Netflix/zuul/issues/326, the test is valid.
This is how zuul in Springcloud filters the header returned by downstream services. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.