Skip to content

Payloads of type application/json with content-length specified now fail if length > 8192 bytes #15

@zarquon5

Description

@zarquon5

With the recent fix for handling binary payloads, we've discovered a new issue that did not occur with version 3.0.6: if you try to send a payload with a content-type of application/json, and a specified content length > 8192 bytes, then the first 8192 bytes is not preserved.

We have created the following 2 additional test cases for TestFieldStorageModified.py that demonstrates this issue; the first test without an explicit content-length passes, but the second does not:
`

def testRequestJSONLargeWithoutContentLength(self):
    value = 'a'*8200
    import json
    d = {'test':value}
    payload = json.dumps(d)
    fs = FieldStorage(
        fp=BytesIO(payload.encode()),
        environ={'REQUEST_METHOD': 'POST',
                 'CONTENT_TYPE': 'application/json'})
    self.assertEqual(fs.headers, {
        'content-type': 'application/json'})
    self.assertEqual(fs.type, 'application/json')
    self.assertEqual(fs.length, -1)
    self.assertEqual(fs.bytes_read, 8212)
    assert fs.file.read() == payload

def testRequestJSONLargeWithContentLength(self):
    value = 'a'*8200
    import json
    d = {'test':value}
    payload = json.dumps(d)
    fs = FieldStorage(
        fp=BytesIO(payload.encode()),
        environ={'REQUEST_METHOD': 'POST',
                 'CONTENT_TYPE': 'application/json',
                 'CONTENT_LENGTH': len(payload)})
    self.assertEqual(fs.headers, {
        'content-type': 'application/json', 'content-length': 8212})
    self.assertEqual(fs.type, 'application/json')
    self.assertEqual(fs.length, 8212)
    self.assertEqual(fs.bytes_read, 8212)
    assert fs.file.read() == payload

`

It isn't clear to me yet how the recent changes caused this problem, but these both pass with 3.0.6.

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