Modify the raw url of Django request before all the normal processes

a 夏天 提交于 2019-12-06 16:16:32

问题


This can be a little tricky and I'm not sure if it's correct way. Since iOS6 prevent setting cookie in the web container, my legacy HTML5 Django game which rely much on cookie (session id) won't work again. I am trying the cookieless way, write a middleware to bring the sessid out from the url and save it to request.cookies['sess_id']. I works, but the codebase contains alot url dependent logics which are impossible to change one by one... url may look like,

    GET /sess_e4b817ee8993bdcbc34733feb18951ff/m/stage/quest/

now I'm thinking about remove the sess part from the url to make it back to

    GET /m/stage/quest/

and all the on-going process will need no change. I guess I can modified the original property of the django request object. Which property to modify? any other better idea? Thanks.


回答1:


You can just re-include your URLs with a prefix, no need to change anything.

url(r'^(?P<sessionid>sess_[a-f0-9]+)/', include('your_urls')),



回答2:


The final way I adopt is to change the iOS container to accept cookie, and no need to change the server side any more. some code for reference,

-(void)applicationDidBecomeActive:(UIApplication *)application {    
isInternetconnectionUp = [self checkInternetConnection];
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
}


来源:https://stackoverflow.com/questions/12533934/modify-the-raw-url-of-django-request-before-all-the-normal-processes

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