在所有正常进程之前修改Django请求的原始URL [英] Modify the raw url of Django request before all the normal processes

查看:101
本文介绍了在所有正常进程之前修改Django请求的原始URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能有点棘手,我不知道这是否正确。由于iOS6无法在网络容器中设置Cookie,因此我依赖于Cookie(会话ID)的旧版HTML5 Django游戏将无法再次运行。我正在尝试无味的方式,写一个中间件,把这个sessid从url中删除,并保存到request.cookies ['sess_id']。我的工作,但代码库包含一个url依赖逻辑,这是不可能一个接一个地改变... url可能看起来像,

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/

现在我在想删除sess部分从网址返回到

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

    GET /m/stage/quest/

所有正在进行的过程都不需要改变。我想我可以修改django请求对象的原始属性。哪个属性要修改?任何其他更好的主意?谢谢。

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.

推荐答案

我采用的最后一种方法是将iOS容器更改为接受cookie,而无需更改服务器端再说了一些代码供参考,

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];
}

这篇关于在所有正常进程之前修改Django请求的原始URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆