1. spring:
    2. cloud:
    3. gateway:
    4. #设置路由:路由id、路由到微服务的uri、断言
    5. routes:
    6. - id: order_route #路由ID,全局唯一
    7. uri: http://localhost:8020 #目标微服务的请求地址和端口
    8. #配置过滤器工厂
    9. filters:
    10. - AddRequestHeader=X-Request-color, red #添加请求头

    测试http://localhost:8888/order/testgateway

    1. @GetMapping("/testgateway")
    2. public String testGateway(HttpServletRequest request) throws Exception {
    3. log.info("gateWay获取请求头X-Request-color:"
    4. +request.getHeader("X-Request-color"));
    5. return "success";
    6. }
    7. @GetMapping("/testgateway2")
    8. public String testGateway(@RequestHeader("X-Request-color") String color) throws Exception {
    9. log.info("gateWay获取请求头X-Request-color:"+color);
    10. return "success";
    11. }

    添加请求头 - 图1