Skip to content

wsgi request fails if the request contains HTTP_CONTENT_LENGTH #245

@raptium

Description

@raptium

wsgi.py reads content_length string from environ['HTTP_CONTENT_LENGTH'] and never converts it into int.

Traceback (most recent call last):
  File "/home/hguan/Desktop/raad/www/wsgi.py", line 34, in application
    return tornado_application(environ, start_response)
  File "/home/hguan/Desktop/raad/www/tornado/wsgi.py", line 77, in __call__
    handler = web.Application.__call__(self, HTTPRequest(environ))
  File "/home/hguan/Desktop/raad/www/tornado/wsgi.py", line 116, in __init__
    self.headers["Content-Length"])
TypeError: an integer is required

Actually Content-Length is first read from environ['CONTENT_LENGTH'] and it gets converted into int. However, if HTTP_CONTENT_LENGTH also presents, it will overwrite self.header['Content-Length'] with a str.

if environ.get("CONTENT_LENGTH"):
    self.headers["Content-Length"] = int(environ["CONTENT_LENGTH"])
for key in environ:
    if key.startswith("HTTP_"):
        self.headers[key[5:].replace("_", "-")] = environ[key]
if self.headers.get("Content-Length"):
    self.body = environ["wsgi.input"].read(
        self.headers["Content-Length"])

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