Skip to content

Commit

Permalink
1.6.1dev: fix Request.send not set Content-Length header for a `b…
Browse files Browse the repository at this point in the history
…ytes` instance (closes #13761)

git-svn-id: http://trac.edgewall.org/intertrac/log:/branches/1.6-stable@17831 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
jomae committed Jun 25, 2024
1 parent 78185ae commit 9a91398
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion trac/web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ def _send(self, content, content_type='text/html', status=200,
self.send_header('Cache-Control', 'must-revalidate')
self.send_header('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT')
self.send_header('Content-Type', content_type + ';charset=utf-8')
if isinstance(content, str):
if isinstance(content, bytes):
self.send_header('Content-Length', len(content))
self.end_headers(exc_info)

Expand Down
11 changes: 11 additions & 0 deletions trac/web/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ def test_write_unicode(self):
with self.assertRaises(ValueError):
req.write((b'F', 'öo'))

def test_send_bytes(self):
req = _make_req(_make_environ(method='GET'))
with self.assertRaises(RequestDone):
req.send(b'\xef\xbb\xbf')
self.assertEqual('3', req.headers_sent.get('Content-Length'))

def test_send_unicode(self):
req = _make_req(_make_environ(method='GET'))
with self.assertRaises(ValueError):
req.send(u'\ufeff')

def test_send_iterable(self):
def iterable():
yield b'line1,'
Expand Down

0 comments on commit 9a91398

Please sign in to comment.