Python 3.5 HTTP服务器端重定向测试脚本
来源:互联网 发布:2017年8月进出口数据 编辑:程序博客网 时间:2024/05/17 15:01
#!/usr/bin/python3import sysimport socketserverimport socketimport http.serverimport threadingimport io# Use supplied portif sys.argv[1:]: port = int(sys.argv[1])else: port = 8889 class RedirectTestHandler(http.server.SimpleHTTPRequestHandler): def send_html_content(self, html_content): length = len(html_content) self.send_header("Content-Type", "text/html") self.send_header("Content-Length", str(length)) self.send_header("Connection", "close") self.send_header("Cache-control", "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform") self.send_header("Pragma", "no-cache") self.end_headers() f = io.BytesIO() f.write(html_content) f.seek(0) self.copyfile(f, self.wfile) def do_GET(self): print("[%s]path=%s" % (threading.current_thread(), self.path)) if self.path[1:]=='': path_num = 0 else: try: path_num = int(self.path[1:]) except ValueError: http.server.SimpleHTTPRequestHandler.do_GET(self) #默认还是基类的实现 return if path_num==20: #重定向最大次数限制 self.send_response(200) self.send_html_content(b"<body>Redirect Test OK!</body>") # b前缀代表bytes对象,默认是str对象 else: path_num += 1 self.send_response(307, "Location Moved") self.send_header("Location", "/%d" % path_num) #FIXME:站内path重定向 和 重定向到外部网站 有什么不同?CORS安全检查? self.send_header("Connection", "close") #也许测试重定向不需要? self.send_header("Cache-control", "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform") self.send_header("Pragma", "no-cache") self.end_headers() # # set up and run the server # bind_addr = ('',port) handler = RedirectTestHandler #CGIHTTPServer.CGIHTTPRequestHandlerhttpd = socketserver.ThreadingTCPServer(bind_addr, handler)sa = httpd.socket.getsockname()print("Serving Redirect Test Server on", sa[0], "port", sa[1], "...")httpd.serve_forever()
0 0
- Python 3.5 HTTP服务器端重定向测试脚本
- 服务器端重定向
- java服务器端重定向
- Servlet/JSP服务器端重定向
- 再谈Redirect(客户端重定向)和Dispatch(服务器端重定向)
- Redirect(客户端重定向)和Dispatch(服务器端重定向)
- 再谈Redirect(客户端重定向)和Dispatch(服务器端重定向)
- 服务器端重定向的两个技巧
- Server.Transfer()方法服务器端重定向后,相对路径问题
- 在客户端重定向
- nginx服务端重定向
- 简单http和https服务器python脚本
- 测试HTTP接口的python自动化脚本
- python多线程http压力测试脚本
- HTTP重定向服务器
- JSF点滴积累--服务端重定向
- 数据库镜像之客户端重定向
- 客户端重定向与服务器端转发
- php学习第二天----基础语法4
- Android-调用系统照相机
- 多线程同步辅助类——CountDownLatch
- 取消eclipse代码自动换行
- 写一个框架的详细步骤
- Python 3.5 HTTP服务器端重定向测试脚本
- 一个小项目(爬虫)的诞生全过程
- 内容提供者,ContentProvider的使用
- 使用AndroidStudio无法使用drawable下的资源,只能使用mipmap目录下的资源?求救大神
- 友元类与友元函数的继承与传递问题
- LeetCode-79.Word Search
- JavaScript---网络编程(3)-Object、String、Array对象和prototype属性
- Linux学习之字符串截取
- 从零开始学React Native App开发