开发者

How can I receive percent encoded slashes with Django on App Engine?

开发者 https://www.devze.com 2023-01-03 05:37 出处:网络
开发者_运维技巧I\'m using Django with Google\'s App Engine. I want to send information to the server with percent encoded slashes.A request like http:/localhost/turtle/waxy%2Fsmooth that would match
开发者_运维技巧

I'm using Django with Google's App Engine.

I want to send information to the server with percent encoded slashes. A request like http:/localhost/turtle/waxy%2Fsmooth that would match against a URL like r'^/turtle/(?P<type>([A-Za-z]|%2F)+)$'. The request gets to the server intact, but sometime before it is compared against the regex the %2F is converted into a forward slash.

What can I do to stop the %2Fs from being converted into forward slashes? Thanks!


os.environ['PATH_INFO'] is decoded, so you lose that information. Probably os.environ['REQUEST_URI'] is available, and if it is available it is not decoded. Django only reads PATH_INFO. You could probably do something like:

request_uri = environ['REQUEST_URI']
request_uri = re.sub(r'%2f', '****', request_uri, re.I)
environ['PATH_INFO'] = urllib.unquote(request_uri)

Then all cases of %2f are replaced with **** (or whatever you want to use).

0

精彩评论

暂无评论...
验证码 换一张
取 消