简体   繁体   English

从烧瓶响应中删除标题

[英]Remove Headers from Flask Response

I am trying to develop a web service back-end for an Alexa skill, and this requires me to have very specific headers in the HTTP response. 我正在尝试为Alexa技能开发Web服务后端,这要求我在HTTP响应中具有非常特定的标头。

Looking at the details of my response (using hurl.it), I have a whole bunch of HTTP headers that Amazon doesn't want. 查看响应的详细信息(使用hurl.it),我有一堆Amazon不需要的HTTP标头。 How can I remove the 'X-Clacks-Overhead', the 'Server', etc., responses. 如何删除“ X-Clacks-Overhead”,“ Server”等响应。

I am using Flask and Python 3. 我正在使用Flask和Python 3。

You can't, but I seriously doubt that anyone would write code that would fall down when there were extra headers fields in a request. 您不能,但是我严重怀疑有人会在请求中有多余的标头字段时编写会掉下来的代码。 Perhaps you're misinterpreting the error. 也许您是在误解错误。

If your header is actually being set by Flask, you can remove it from the headers dict on the response by using Flask's after_request function/decorator: 如果您的标头实际上是由Flask设置的,则可以使用Flask的after_request函数/装饰器将其从响应的标头字典中删除:

@app.after_request
def remove_header(response):
    del response.headers['X-Some-Custom-Header']

    return response

With the likes of Server , it's likely this is being set by an upstream provider and not Flask directly, so you'd need to remove it from whatever is proxying the request from Flask and outputting to the user. 对于类似Server ,很可能是由上游提供商而不是直接由Flask设置的,因此您需要将其从代理Flask的请求并输出给用户的任何内容中删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM