问题的起因:
生产环境项目编辑用户信息后,发现编辑完后没办法跳转页面,一直停留在当前页面,看代码发现是有通过 redirect: /xxx/xxx 重定向跳转页面,但明显不起作用了
排查问题的心路历程:
1、看了接口请求,是有生成Location的,但是明显使用的协议不一样,Request URL是https,而Location确实http
2、查阅网上许多文章,都说是配置springMVC的属性redirectHttp10Compatible为false,默认true是使用HTTP 1.0协议,即http。
无奈水土不服,配置后还是不行,重定向链接依然是http
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/static/views/"/>
<property name="suffix" value=".jsp"/>
<property name="redirectHttp10Compatible" value="false"/>
</bean>
3、再去网上狂翻答案,拜读到一篇似乎可以解决的文章(链接:一个HTTPS转HTTP的Bug,他们竟然忍了2年?原谅我无法接受,加班改了! - 知乎),刚好也是用了Shiro的FormAuthenticationFilter,怀疑WebUtils的issueRedirect方法中设置http10Compatible为true,但应该影响登录的跳转,不影响其它业务才对,抱着疑问试了,也是解决不了。
4、最终debug代码,发现Location的协议是从request.getScheme()中获取的,于是又去网上翻答案,终于解决问题,感谢伟大的网友!(问题解决:通过https访问页面,request.getScheme()获取到的却是http_getscheme总是读取到http-CSDN博客)
由于一开始解决问题的切入点关注在springMVC上面,忽略了线上用的是外部Tomcat,不同于springboot的集成Tomcat,因此线上环境Tomcat的server.xml配置还需要另外增加 scheme="https" secure="true" 配置
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding='UTF-8'
scheme="https" secure="true"/>
至此问题fix了,done!!!!!!