ruby - How to safely encode cidr notation in url?
问题描述
I'm working on an application that does some basic network management. Due to constraints outside of the scope of this application, there's a need to encode a cidr block (eg 127.0.0.1/32
) into the url. For instance, an endpoint route might look something like this post "/home/network/:user/:cidr"
. In most cases, one could easily send the cidr as a string in the payload but that is not an option here.
I know that .
is a valid url character and that /
can be encoded with %2F
. Naively combining these and attempting to post against that endpoint like so: /home/network/janedoe/127.0.0.1%2F32
404ed which makes me think Sinatra isn't able to properly parse that url parameter. I've also tried using the URI
module to encode the cidr string with no luck so far.
Perhaps there's an easier way to think about encoding the cidr block into the url that makes for easy extraction in the endpoint.
解决方案
推荐阅读
- python - 获取从数组到变量的所有内容
- reactjs - 检查路由是否有效反应路由器
- c# - c# 中的高级元编程是否有一些行业“标准”?
- jenkins - Jenkins 在失败时打印敏感变量
- mapbox - 有什么方法可以为 mapbox 中同一图层上的每个功能在悬停时提供不同的光标样式?
- angular - Angular 9 异步管道和搜索过滤器
- mysql - 迁移到 MySQL 8 后,Hibernate Criteria 查询不适用于日期时间列
- javascript - 在我设置某些状态后尝试将数据从子组件传递到安装上的父组件时出现恒定的无限循环
- methods - 哈希表是否支持与二叉搜索树相同的方法?
- spring-boot - 如何在所有客户端的春季会话空闲时间后重定向到登录页面