【问题现状】
application.yml 配置如下属性:
yaml
server:
servlet:
context-path: /learning
直接访问:http://localhost:8888/learning 路径时,会返回302的响应状态;并跳转路径:http://localhost:8888/learning/ (原路径后多了个斜杠/)
源码分析:
org.apache.tomcat.util.net.NioEndpoint.SocketProcessor#doRun
org.apache.coyote.AbstractProtocol.ConnectionHandler#process
org.apache.coyote.AbstractProcessorLight#process
org.apache.coyote.http11.Http11Processor#service
org.apache.catalina.connector.CoyoteAdapter#service
此时 status 还为 200,执行过后,status 变为 302,如下所示:
详细看 org.apache.catalina.connector.CoyoteAdapter#postParseRequest 方法:
再深入分析 request.getMappingData().redirectPath 的值是怎么来的:
org.apache.catalina.mapper.Mapper#map
org.apache.catalina.mapper.Mapper#internalMap
org.apache.catalina.mapper.Mapper#internalMapWrapper
扩展学习: