在我的GAE應用程序中,我使用webapp2.RequestHandler.initialize
對請求做了自定義內容。
直到幾天前,更改os.environ['PATH_INFO']
確實會影響在RequestHandler上調用self.request.path,並且它反映了已更改的請求路徑。 (並且這仍然可以在SDK上正常工作)webapp2,self.request.path更改GAE上的問題
現在它不再起作用了。當然因爲它有很多問題。 我明白這可能是一個邊緣案例,但是這個變化的原因是什麼?
受影響的代碼:
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
你爲什麼改變路徑而不向頭添加新實體? –
我明白了,但我想盡可能地保持默認實現,以便能夠使用所有self.request道具和功能。但我當然知道如何解決這個問題。仍然不明白過去幾天發生了什麼變化。 – aschmid00