cookie必须包含username=fox的时候才能请求通过,否则不让通过

  1. spring:
  2. cloud:
  3. gateway:
  4. #设置路由:路由id、路由到微服务的uri、断言
  5. routes:
  6. - id: order_route #路由ID,全局唯一
  7. uri: http://localhost:8020 #目标微服务的请求地址和端口
  8. predicates:
  9. # Cookie匹配
  10. - Cookie=username, fox

代码地址

https://gitee.com/zjj19941/ZJJ_Neaten5.10/tree/master/ZJJ_Gateway/demo04

测试

yml配置:

  1. routes:
  2. - id: order_route #路由ID,全局唯一,建议配合服务名
  3. # uri参数可以直接去指定ip端口,也可以指定负载均衡lb开头
  4. #uri: http://localhost:8020 #目标微服务的请求地址和端口
  5. uri: lb://mall-order #lb 整合负载均衡器ribbon,loadbalancer
  6. predicates:
  7. # #Path路径匹配
  8. - Path=/order/**
  9. # Cookie匹配
  10. - Cookie=username, fox

完全匹配才能通过
image.png
没匹配就报404
image.png

完全没有也会报404
image.png