Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

[python] non ascii HTTP headers  #868

@RomainMou

Description

@RomainMou

Hello,

I'm trying to replace gunicorn with Unit 1.29.1 for some Django projects, but I have some weirds issues with the HTTP headers contents:

(Pdb) request.META.get("HTTP_DNT")
'1'
(Pdb) request.META.get("HTTP_DNT").isascii()
False
(Pdb) test = request.META.get("HTTP_DNT")
(Pdb) test.isascii()
False
(Pdb) test2 = (test + '.')[:-1]
(Pdb) test == test2
True
(Pdb) test2.isascii()
True

It seams that the string is encoded in a way that Python does not considered it to be an ASCII string. I can also see that it seams that the strings have a different memory size between the non ASCII and the ASCII version.

(Pdb) from sys import getsizeof
(Pdb) getsizeof(test)
74
(Pdb) getsizeof(test2)
50
(Pdb) import ctypes
(Pdb) ctypes.string_at(id(test), getsizeof(test))
b'\x02\x00\x00\x00\x00\x00\x00\x00\xa0\xc8\x9e\xddT\x7f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xa4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x001\x00'
(Pdb) ctypes.string_at(id(test2), getsizeof(test2))
b'K\x00\x00\x00\x00\x00\x00\x00\xa0\xc8\x9e\xddT\x7f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x06\x1b\xaa\x81s-=\xed\xe5\xe5L\xddT\x7f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x001\x00'

I couldn't manage to reproduce this issue with Gunicorn:

(Pdb) request.META.get("HTTP_DNT")
'1'
(Pdb) test = request.META.get("HTTP_DNT")
(Pdb) test.isascii()
True
(Pdb) from sys import getsizeof
(Pdb) getsizeof(test)
50

Is this normal? Did I miss some configuration?

Metadata

Metadata

Assignees

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