Skip to content

Commit

Permalink
Merge pull request #20 from bepatient-fr/FIx_content_length_header_no…
Browse files Browse the repository at this point in the history
…t_computed_on_bytes

Fix Content-Length header not calculated on bytes length
  • Loading branch information
M3te0r authored Apr 28, 2022
2 parents f148e3d + 237f651 commit f1ada40
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions ikaaro/web/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,18 @@ def application(environ, start_response):
log.error("Internal error : {}".format(tb), exc_info=True)
context.set_default_response(500)
finally:
data = context.entity
if isinstance(data, str):
data = data.encode("utf-8")
headers = context.header_response
if context.content_type:
headers.append(('Content-Type', context.content_type))
if context.entity and not isinstance(context.entity, Reference):
headers.append(('Content-Length', str(len(context.entity))))
if data and not isinstance(data, Reference):
headers.append(('Content-Length', str(len(data))))
status = context.status or 500
status = '{0} {1}'.format(status, reason_phrases[status])
start_response(str(status), headers)
data = context.entity
if isinstance(data, str):
yield data.encode("utf-8")
else:
yield data
yield data


try:
Expand Down
2 changes: 1 addition & 1 deletion scripts/icms-forget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Copyright (C) 2009 Juan David Ibáñez Palomar <[email protected]>
#
Expand Down
2 changes: 1 addition & 1 deletion scripts/icms-start.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Copyright (C) 2005-2007 Juan David Ibáñez Palomar <[email protected]>
# Copyright (C) 2006 Hervé Cauwelier <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion scripts/icms-stop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Copyright (C) 2005-2007 Juan David Ibáñez Palomar <[email protected]>
# Copyright (C) 2007 Sylvain Taverne <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion scripts/icms-update-catalog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Copyright (C) 2007 Hervé Cauwelier <[email protected]>
# Copyright (C) 2007-2008 Juan David Ibáñez Palomar <[email protected]>
Expand Down

0 comments on commit f1ada40

Please sign in to comment.