Springboot基于Redisson实现Redis分布式可重入锁源码解析
451
2022-08-19
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.cohttp://yote.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();
}
List
Map
template.headers(headers);
}
}
};
}
protected static void mineHeadersHandle(MimeHeaders mimeHeaders) {
mimeHeadershttp://.removeHeader(HttpHeaders.CONTENT_TYPE);
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~