doudouwen2763 2019-05-07 10:26
浏览 41
已采纳

Golang Gorilla发送301的“ //” URL

I have two route configured as following

  • GET /api/store/{store_id}/books
  • GET /api/store/{store_id}

When an API call comes for the first URL without {store_id} parameter, like /api/store//books, Gorilla would somehow send a 301 /api/store/books to client. This is causing me problem because it acutally matched the second route. Gorilla would treat books as the {store_id} parameter.

How do I configure Gorilla to return 404 or other error code when receiving // in URLs?

I am using Gorilla v1.7.0.

  • 写回答

1条回答 默认 最新

  • doushi9856 2019-05-07 15:01
    关注

    By default mux will clean the URL. You can set the router.SkipClean(true) parameter to avoid that.

    When true, if the route path is "/path//to", it will remain with the double slash. This is helpful if you have a route like: /fetch/http://xkcd.com/534/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度