summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2016-10-08 16:41:51 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2016-10-08 16:41:51 (GMT)
commit42bb1615c096d6485d36f6a07eab36f2e2e95b3b (patch)
treed5b3a9663302e1a59ba7aad9e0aa489de6650bf6 /library
parentbe3376f36c02b2b317b509aed67b7751e656ecbb (diff)
parent0ac8f1e19818ac7aa6fd35de8e3190bcd24dcb6d (diff)
downloadtcl-42bb1615c096d6485d36f6a07eab36f2e2e95b3b.zip
tcl-42bb1615c096d6485d36f6a07eab36f2e2e95b3b.tar.gz
tcl-42bb1615c096d6485d36f6a07eab36f2e2e95b3b.tar.bz2
[838e99a76d] Ensure that encodings are handled with application/xml and friends.
Diffstat (limited to 'library')
-rw-r--r--library/http/http.tcl34
1 files changed, 33 insertions, 1 deletions
diff --git a/library/http/http.tcl b/library/http/http.tcl
index 5a05fa0..dfd6996 100644
--- a/library/http/http.tcl
+++ b/library/http/http.tcl
@@ -1047,7 +1047,7 @@ proc http::Event {sock token} {
fconfigure $sock -translation binary
if {
- $state(-binary) || ![string match -nocase text* $state(type)]
+ $state(-binary) || [IsBinaryContentType $state(type)]
} {
# Turn off conversions for non-text data
set state(binary) 1
@@ -1183,6 +1183,38 @@ proc http::Event {sock token} {
}
}
+# http::IsBinaryContentType --
+#
+# Determine if the content-type means that we should definitely transfer
+# the data as binary. [Bug 838e99a76d]
+#
+# Arguments
+# type The content-type of the data.
+#
+# Results:
+# Boolean, true if we definitely should be binary.
+
+proc http::IsBinaryContentType {type} {
+ lassign [split [string tolower $type] "/;"] major minor
+ if {$major eq "text"} {
+ return false
+ }
+ # There's a bunch of XML-as-application-format things about. See RFC 3023
+ # and so on.
+ if {$major eq "application"} {
+ set minor [string trimright $minor]
+ if {$minor in {"xml" "xml-external-parsed-entity" "xml-dtd"}} {
+ return false
+ }
+ }
+ # Not just application/foobar+xml but also image/svg+xml, so let us not
+ # restrict things for now...
+ if {[string match "*+xml" $minor]} {
+ return false
+ }
+ return true
+}
+
# http::getTextLine --
#
# Get one line with the stream in blocking crlf mode