龙卷风怎么可以set_status307

How can tornado set_status 307

我在 python 2.7 中使用 tornado 4.3。我想将一个请求重定向到另一个 one.For 示例,当我 POST http://127.0.0.1/ , I wanna it posting to https://myip.ipip.net/.This 可以由 nginx 使用下面的 conf

完成时
return  307  $scheme://myip.ipip.net$request_uri;

但现在目标 URL 并不总是相同的,所以我不能在 nginx 中进行硬编码。 由于我的服务器是 tornado ,我应该使用代码让它工作。 正如我们所知,tornado 支持使用 self.set_status(HTTP_CODE) 设置 HTTP 代码。 但是当我设置 307 时它响应 302 到 client.What 的错误 ?

这是我的代码

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def post(self):
        self.set_status(307)
        self.redirect("https://myip.ipip.net/") #

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

这是我的测试 curl.Tornado 虽然我设置了 307,但响应了 302。

curl -LI 127.0.0.1:8888 -XPOST

结果如下

HTTP/1.1 302 Found
Date: Wed, 10 May 2017 07:31:17 GMT
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Location: https://myip.ipip.net/
Server: TornadoServer/4.3

HTTP/1.1 200 OK
Server: NewDefend
Date: Wed, 10 May 2017 07:31:18 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 69
Connection: keep-alive
X-Cache:  from ctl-zj-122-228-198-138

谢谢!

redirect takes a status parameter:

class MainHandler(tornado.web.RequestHandler):
    def post(self):
        self.redirect("https://myip.ipip.net/", status=307)