找到你要的答案

Q:How can I tell Flask not to add host/scheme info to my redirect?

Q:我怎样才能告诉烧瓶不添加主机/计划信息到我的重定向?

I want to use Flask to redirect RTMP streams, where the new stream name is contained in the Location header of a 30x redirect. However, Flask always adds the host/scheme URL info to my redirect:

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

Results in:

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

Where I want the Location to just be:

Location: new-stream-name

Thanks!

EDIT: I'm using nginx-rtmp stream redirects to control how my publishers/viewers authenticate with streams.

UPDATE:

The solution was rather easy with subclassing Response:

from flask import Response

class FixedLocationResponse(Response):
    autocorrect_location_header = False


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

Results in:

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

我想用瓶重定向rtmp流,在新的流名称包含在30倍将头的位置。然而,烧瓶总是添加主机/计划URL信息到我的重定向:

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

结果:

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

我想要的位置只是:

Location: new-stream-name

谢谢!

编辑:我使用nginx的RTMP流重定向控制我的出版商/观众验证的流。

更新:

解决方案是用子类化反应而易:

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
python  flask  wsgi  werkzeug