SpringCloud Feign请求头删除修改的操作代码
Feign请求头修改删除操作
@Configuration public class ClientConfiguration { @Bean public RequestInterceptor headerInterceptor() { return new RequestInterceptor() { @Override public void apply(RequestTemplate template) { HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); if (httpServletRequest.getRequestURI().contains(template.url())) { try { Field connectorField = ReflectionUtils.findField(SecurityContextHolderAwareRequestWrapper.class, "request"); connectorField.setAccessible(true); FirewalledRequest firewalledRequest = (FirewalledRequest) connectorField.get(httpServletRequest); if(Objects.isNull(firewalledRequest)) return; Field firewalledField = ReflectionUtils.findField(FirewalledRequest.class, "request"); firewalledField.setAccessible(true); RequestFacade requestFacade = (RequestFacade) firewalledField.get(firewalledRequest); if(Objects.isNull(requestFacade)) return; connectorField = ReflectionUtils.findField(RequestFacade.class, "request"); firewalledField.setAccessible(true); Request connectorRequest = (Request) connectorField.get(requestFacade); if(Objects.isNull(connectorRequest)) return; Field coyoteField = ReflectionUtils.findField(Request.class, "coyoteRequest", org.apache.coyote.Request.class); coyoteField.setAccessible(true); org.apache.coyote.Request coyoteRequest = (org.apache.coyote.Request) coyoteField.get(connectorRequest); if(Objects.isNull(coyoteRequest)) return; Field mimeHeadersField = ReflectionUtils.findField(org.apache.coyote.Request.class, "headers", MimeHeaders.class); mimeHeadersField.setAccessible(true); MimeHeaders mimeHeaders = (MimeHeaders) mimeHeadersField.get(coyoteRequest); mineHeadersHandle(mimeHeaders); } catch (IllegalAccessException e) { e.printStackTrace(); } ListcontentTypeList = Lists.newArrayList("application/json;charset=UTF-8"); Map > headers = ImmutableMap.of(HttpHeaders.CONTENT_TYPE, contentTypeList); template.headers(headers); } } }; } protected static void mineHeadersHandle(MimeHeaders mimeHeaders) { mimeHeaders.removeHeader(HttpHeaders.CONTENT_TYPE); } }
到此这篇关于SpringCloudFeign请求头删除修改的操作代码的文章就介绍到这了,更多相关SpringCloudFeign请求头内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
X 关闭
X 关闭
- 15G资费不大降!三大运营商谁提供的5G网速最快?中国信通院给出答案
- 2联想拯救者Y70发布最新预告:售价2970元起 迄今最便宜的骁龙8+旗舰
- 3亚马逊开始大规模推广掌纹支付技术 顾客可使用“挥手付”结账
- 4现代和起亚上半年出口20万辆新能源汽车同比增长30.6%
- 5如何让居民5分钟使用到各种设施?沙特“线性城市”来了
- 6AMD实现连续8个季度的增长 季度营收首次突破60亿美元利润更是翻倍
- 7转转集团发布2022年二季度手机行情报告:二手市场“飘香”
- 8充电宝100Wh等于多少毫安?铁路旅客禁止、限制携带和托运物品目录
- 9好消息!京东与腾讯续签三年战略合作协议 加强技术创新与供应链服务
- 10名创优品拟通过香港IPO全球发售4100万股 全球发售所得款项有什么用处?