summaryrefslogtreecommitdiff
path: root/cherrypy/lib/encoding.py
diff options
context:
space:
mode:
authorzakj <none@none>2007-10-22 01:29:33 +0000
committerzakj <none@none>2007-10-22 01:29:33 +0000
commit0b9c5fcc59faf80fa0db0b6ad5c6d22ed6bcea0d (patch)
tree8d9b4c60b56b3ad17c8191df0bb246a448328fc7 /cherrypy/lib/encoding.py
parent0325cd3d9b3324f1c628e94349d893b82649bb78 (diff)
downloadcherrypy-git-0b9c5fcc59faf80fa0db0b6ad5c6d22ed6bcea0d.tar.gz
Primarily to support text-based content types that do not start with "text/",
added text_only and add_charset boolean arguments to lib.encoding.encode(), both defaulting to True.
Diffstat (limited to 'cherrypy/lib/encoding.py')
-rw-r--r--cherrypy/lib/encoding.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py
index 49844c64..b21c5f88 100644
--- a/cherrypy/lib/encoding.py
+++ b/cherrypy/lib/encoding.py
@@ -50,7 +50,7 @@ def decode_params(encoding):
# Encoding
-def encode(encoding=None, errors='strict'):
+def encode(encoding=None, errors='strict', text_only=True, add_charset=True):
# Guard against running twice
if getattr(cherrypy.request, "_encoding_attempted", False):
return
@@ -59,10 +59,11 @@ def encode(encoding=None, errors='strict'):
ct = cherrypy.response.headers.elements("Content-Type")
if ct:
ct = ct[0]
- if ct.value.lower().startswith("text/"):
+ if (not text_only) or ct.value.lower().startswith("text/"):
# Set "charset=..." param on response Content-Type header
ct.params['charset'] = find_acceptable_charset(encoding, errors=errors)
- cherrypy.response.headers["Content-Type"] = str(ct)
+ if add_charset:
+ cherrypy.response.headers["Content-Type"] = str(ct)
def encode_stream(encoding, errors='strict'):
"""Encode a streaming response body.