在我的 GAE 应用程序中,我webapp2.RequestHandler.initialize
用来对请求执行自定义操作。
直到几天前,更改os.environ['PATH_INFO']
确实影响了在 RequestHandler 上调用 self.request.path 并且它反映了更改的请求路径。(这在 SDK 上仍然可以正常工作)
现在它不再起作用了。当然,我因此遇到了很大的问题。我知道这可能是一个极端情况,但这种变化的原因是什么?
受影响的代码:
class BaseHandler(webapp2.RequestHandler):
def initialize(self, request, response):
ns, path = get_namespace(os.environ)
namespace_manager.set_namespace(ns)
os.environ['namespace'] = ns
# request.path reflects the incoming path
path = os.environ.get('PATH_INFO')
prefix = '/%s'%ns
if ns and path.startswith(prefix):
# the request.path has to be changed here...
newpath = path[len(prefix):]
# here i change the path_info in os.environ to the new
# path
os.environ['PATH_INFO'] = newpath or '/'
super(BaseHandler, self).initialize(request, response)
# request.path and self.request.path here are still unchanged.
# up to a few days ago here the path was reflecting the changes