diff -r 8b4b8f5d7321 Doc/library/http.client.rst --- a/Doc/library/http.client.rst Wed Jun 11 04:36:09 2014 -0700 +++ b/Doc/library/http.client.rst Wed Jun 11 14:56:30 2014 +0200 @@ -521,8 +521,12 @@ Send data to the server. This should be used directly only after the :meth:`endheaders` method has been called and before :meth:`getresponse` is - called. + called. *data* can be a string object, a bytes object, an array object, a + file-like object that supports a .read() method, or an iterable object. + .. versionchanged:: 3.5 + if a file object is passed and the platform supports it use + high-performance :func:`os.sendfile` to transmit the file. .. _httpresponse-objects: diff -r 8b4b8f5d7321 Lib/http/client.py --- a/Lib/http/client.py Wed Jun 11 04:36:09 2014 -0700 +++ b/Lib/http/client.py Wed Jun 11 14:56:30 2014 +0200 @@ -942,13 +942,15 @@ encode = True if self.debuglevel > 0: print("encoding file using iso-8859-1") - while 1: - datablock = data.read(blocksize) - if not datablock: - break - if encode: + if encode: + while 1: + datablock = data.read(blocksize) + if not datablock: + break datablock = datablock.encode("iso-8859-1") - self.sock.sendall(datablock) + self.sock.sendall(datablock) + else: + self.sock.sendfile(data) return try: self.sock.sendall(data) diff -r 8b4b8f5d7321 Lib/test/test_httplib.py --- a/Lib/test/test_httplib.py Wed Jun 11 04:36:09 2014 -0700 +++ b/Lib/test/test_httplib.py Wed Jun 11 14:56:30 2014 +0200 @@ -55,6 +55,9 @@ self.sendall_calls += 1 self.data += data + def sendfile(self, file): + self.data += file.read() + def makefile(self, mode, bufsize=None): if mode != 'r' and mode != 'rb': raise client.UnimplementedFileMode()