I am trying to get requests to pass on encoded strings in a URL. For example:
/application/controller/function/hello%20world
so that in my function I can access request.args and get a string that I can unquote().
I tried modifying rewrite.py to not convert %20 but that caused some error. Something else is catching these requests somewhere that I am having trouble finding. I noticed the httpserver.log file has:
127.0.0.1, 2011-09-02 00:12:09, GET, /application/controller/function/hello world, HTTP/1.1, 200, 0.169954
with the space already converted. Maybe that gives a hint. Where are the url’s getting unencoded?
Below are the contents of my routes file:
#!/usr/bin/python
# -*- coding: utf-8 -*-
default_application = 'chips'
default_controller = 'default'
default_function = 'index'
routes_onerror = [
(r'*/404', r'/chips/static/404.html')
,(r'*/*', r'/chips/static/error.html')
]
By default, web2py will not allow special characters in args except ‘@’, ‘-‘, ‘=’, and ‘.’. To override that behavior, you can add the following to routes.py:
In that case, request.args will be set to
None, and instead you can access the raw args from the URL viarequest.raw_args. Note, though, thatroutes_apps_rawdoes not work if you are using the parameter-based rewrite system (i.e., if your routes.py file includes aroutersdictionary).Note, even with the above change, the Rocket web server included with web2py will still automatically
unquote()the URL, so you’ll get the special characters inrequest.raw_args, but they will already be decoded.If you are instead using the parameter-based rewrite system, you can control which characters are allowed in URL args via the
args_matchkey, which takes a regular expression as its value. The default regex isr'([\w@ -]|(?<=[\w@ -])[.=])*$', which allows ‘@’, ‘-‘, ‘=’, and ‘.’ (with some restrictions on ‘=’ and ‘.’).