Skip to content

Setting items on response.header with bytestrings results in new headers in Python 3 #1986

@jameshiew

Description

@jameshiew

Minimal example below

# coding=utf8
from flask import Flask, Response

app = Flask(__name__)

@app.route('/')
def hello():
    response = Response("!!!")
    response.headers[b'Server'] = 'Flask'
    return response

In Python 2.7.12, the resulting response has a HTTP header of Server: Flask. In Python 3.5.2, the resulting response has HTTP headers of Server: Werkzeug/0.11.10 Python/3.5.2 and b'Server': Flask. Python 2 has the expected behavior.

Testing from within a Python 3 venv, pip freeze output is:

click==6.6
Flask==0.11.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.11.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions