如何告诉Flask不要在重定向中添加主机/方案信息?

2024-10-03 02:44:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用Flask重定向RTMP流,其中新的流名称包含在30x重定向的Location头中。但是,Flask总是在我的重定向中添加主机/方案URL信息:

@app.route("/redirect")
def root():
    return redirect("new-stream-name")

结果:

^{pr2}$

我想要的位置是:

Location: new-stream-name

谢谢!在

{I publisher使用^ m控件对我的流进行身份验证。在

更新:

子类化Response的解决方案相当简单:

from flask import Response

class FixedLocationResponse(Response):
    autocorrect_location_header = False


@app.route("/redirect")
def root():
    return redirect("new-stream-name", Response=FixedLocationResponse)

结果:

HTTP/1.0 302 FOUND
Content-Type: text/html; charset=utf-8
Content-Length: 237
Location: new-stream-name
Server: Werkzeug/0.10.4 Python/2.7.9
Date: Sat, 02 May 2015 19:31:28 GMT

Tags: nameappflasknewstreamreturnresponsedef