学习httpbin源代码记录(二)
来源:互联网 发布:java中service的作用 编辑:程序博客网 时间:2024/05/20 12:22
httpbin源码中关于重定向的实现:
@app.route('/redirect-to', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'TRACE'])def redirect_to(): """302/3XX Redirects to the given URL.""" args = CaseInsensitiveDict(request.args.items()) # We need to build the response manually and convert to UTF-8 to prevent # werkzeug from "fixing" the URL. This endpoint should set the Location # header to the exact string supplied. response = app.make_response('') response.status_code = 302 if 'status_code' in args: status_code = int(args['status_code']) if status_code >= 300 and status_code < 400: response.status_code = status_code response.headers['Location'] = args['url'].encode('utf-8') return response这里主要涉及以下几点:
(1)request对象;
(2)args 这个内容已经在上一篇中讲解
在flask框架中,每一个请求发送到服务器端,请求的所有相关信息都是保存在request中,
request.args就是其中的一个;
然后使用类CaseInsensitiveDict构造一个对象args,并使用request.args作为参数传入;
最后就是使用headers的Location设置目标url;
这里我有一个想法,如果能够很方便的将httpbin中的一段代码复制出来,单独调试,岂不是能够帮助我们快速的学习
只是我暂时没有想到切实可行的方法,也仅仅是修改源代码,添加一个log功能,然后运行能够httpbin;
这样真的是不太方便啊,大家有什么建议没?
阅读全文
0 0
- 学习httpbin源代码记录(二)
- 学习httpbin源码记录(一)
- 学习httpbin源码记录(三)
- 学习httpbin源码记录(四)
- httpbin 学习笔记.
- httpbin
- httpbin
- libdvbpsi 源代码学习(二)
- PhysX学习记录 二
- Linux学习记录(二)
- WCF学习记录二
- PhysX学习记录 二
- netty 学习记录二
- android学习记录<二>
- TMS320F28035学习记录二
- Dubbo学习记录二
- tensorflow(二)学习记录
- JavaScript学习记录(二)
- 程序员的小节日__回文日
- Github学习之Git安装与使用
- 数据类型转换
- Java8以及Java9的一些有用的新特性总结
- 4章 处理器体系结构
- 学习httpbin源代码记录(二)
- Windows下用Git/Github托管代码
- Python 3爬虫小实战(一)—— 豆瓣电影Top250
- 三、JS【JavaScript弱类型的脚本语言】02
- Ubuntu通过命令行设置无线网络连接
- 数据结构-邻接链表的建立和使用
- 数组初识
- 深入学习JavaScript: apply 方法 详解(转)——非常好
- Codeforces GYM 100753J: Souvenirs 题解