Pyramid Replacing Double Forward-Slash in URL Matchdict

半城伤御伤魂 提交于 2020-01-20 08:42:28

问题


Essentially, I'm just building an API redirection route inside of Pyramid to process cross-domain AJAX requests without using JSONP.

I've added a route, like so:

config.add_route("api","/api/{url:.*}")

with which I want to capture URLs like so:

http://domain.com/api/http://location.of/other/api

However, when grabbing the captured URL suffix out of the Request matchdict, I get the following:

http:/location.of/other/api

I'm guessing some escaping has been done during URL processing/matching? How can I avoid this, and get the desired URL with two forward slashes?

Even if I pass the URL in as a GET parameter, the issue remains. Perhaps it's something to do with the way Pyramid's multidicts work?


回答1:


This is a fundamental limitation of any WSGI-based application. URLs are urldecoded and slashes are compacted before the URL is passed to the WSGI app. If you want to preserve the slashes you will need to urlencode them twice. AFAIK there is no way around this using a query string.

I guess I should point out that the original URL is available, but from it you will have to parse out the part you care about yourself. It is in request.url. request.path_info is what Pyramid and most WSGI apps use to dispatch URLs because it contains only the sub-path that is relative to where the app is mounted.



来源:https://stackoverflow.com/questions/10939108/pyramid-replacing-double-forward-slash-in-url-matchdict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!