summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-08-24 13:10:13 (GMT)
committerGuido van Rossum <guido@python.org>2001-08-24 13:10:13 (GMT)
commit833a8d86417f4832f5e3ad742f21fe10378388bb (patch)
treef62da46c685b1b952023dbd946d69eb204c87d8e
parent845fc48bf739fc04ed3e082aec772c2dc72bf1b6 (diff)
downloadcpython-833a8d86417f4832f5e3ad742f21fe10378388bb.zip
cpython-833a8d86417f4832f5e3ad742f21fe10378388bb.tar.gz
cpython-833a8d86417f4832f5e3ad742f21fe10378388bb.tar.bz2
SF patch #454553 by Walter Dörwald: add content-type to FTP URLs, like
for urllib.
-rw-r--r--Lib/urllib2.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index f9e6bf2..5882de6 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -956,11 +956,14 @@ class FTPHandler(BaseHandler):
value in ('a', 'A', 'i', 'I', 'd', 'D'):
type = value.upper()
fp, retrlen = fw.retrfile(file, type)
+ headers = ""
+ mtype = mimetypes.guess_type(req.get_full_url())[0]
+ if mtype:
+ headers += "Content-Type: %s\n" % mtype
if retrlen is not None and retrlen >= 0:
- sf = StringIO('Content-Length: %d\n' % retrlen)
- headers = mimetools.Message(sf)
- else:
- headers = noheaders()
+ headers += "Content-Length: %d\n" % retrlen
+ sf = StringIO(headers)
+ headers = mimetools.Message(sf)
return addinfourl(fp, headers, req.get_full_url())
except ftplib.all_errors, msg:
raise IOError, ('ftp error', msg), sys.exc_info()[2]