Merge pull request #3000 from fuzeman/feature/dev_rtorrent
[rtorrent] Fixed connection bug when using SSL + Basic Auth
This commit is contained in:
@@ -59,20 +59,22 @@ class rTorrent(Downloader):
|
|||||||
return self.rt
|
return self.rt
|
||||||
|
|
||||||
url = cleanHost(self.conf('host'), protocol = True, ssl = self.conf('ssl'))
|
url = cleanHost(self.conf('host'), protocol = True, ssl = self.conf('ssl'))
|
||||||
|
|
||||||
|
# Automatically add '+https' to 'httprpc' protocol if SSL is enabled
|
||||||
|
if self.conf('ssl') and url.startswith('httprpc://'):
|
||||||
|
url = url.replace('httprpc://', 'httprpc+https://')
|
||||||
|
|
||||||
parsed = urlparse(url)
|
parsed = urlparse(url)
|
||||||
|
|
||||||
# rpc_url is only used on http/https scgi pass-through
|
# rpc_url is only used on http/https scgi pass-through
|
||||||
if parsed.scheme in ['http', 'https']:
|
if parsed.scheme in ['http', 'https']:
|
||||||
url += self.conf('rpc_url')
|
url += self.conf('rpc_url')
|
||||||
|
|
||||||
if self.conf('username') and self.conf('password'):
|
self.rt = RTorrent(
|
||||||
self.rt = RTorrent(
|
url,
|
||||||
url,
|
self.conf('username'),
|
||||||
self.conf('username'),
|
self.conf('password')
|
||||||
self.conf('password')
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.rt = RTorrent(url)
|
|
||||||
|
|
||||||
self.error_msg = ''
|
self.error_msg = ''
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -89,13 +89,16 @@ class RTorrent:
|
|||||||
|
|
||||||
def _get_conn(self):
|
def _get_conn(self):
|
||||||
"""Get ServerProxy instance"""
|
"""Get ServerProxy instance"""
|
||||||
if self.username is not None and self.password is not None:
|
|
||||||
|
if self.username and self.password:
|
||||||
if self.scheme == 'scgi':
|
if self.scheme == 'scgi':
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
secure = self.scheme == 'https'
|
||||||
|
|
||||||
return self.sp(
|
return self.sp(
|
||||||
self.uri,
|
self.uri,
|
||||||
transport=BasicAuthTransport(self.username, self.password),
|
transport=BasicAuthTransport(secure, self.username, self.password),
|
||||||
**self.sp_kwargs
|
**self.sp_kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -20,24 +20,46 @@
|
|||||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
from base64 import encodestring
|
from base64 import b64encode
|
||||||
import string
|
import httplib
|
||||||
import xmlrpclib
|
import xmlrpclib
|
||||||
|
|
||||||
|
|
||||||
class BasicAuthTransport(xmlrpclib.Transport):
|
class BasicAuthTransport(xmlrpclib.Transport):
|
||||||
def __init__(self, username=None, password=None):
|
def __init__(self, secure=False, username=None, password=None):
|
||||||
xmlrpclib.Transport.__init__(self)
|
xmlrpclib.Transport.__init__(self)
|
||||||
|
|
||||||
|
self.secure = secure
|
||||||
|
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
|
|
||||||
def send_auth(self, h):
|
def send_auth(self, h):
|
||||||
if self.username is not None and self.password is not None:
|
if not self.username or not self.password:
|
||||||
h.putheader('AUTHORIZATION', "Basic %s" % string.replace(
|
return
|
||||||
encodestring("%s:%s" % (self.username, self.password)),
|
|
||||||
"\012", ""
|
auth = b64encode("%s:%s" % (self.username, self.password))
|
||||||
))
|
|
||||||
|
h.putheader('Authorization', "Basic %s" % auth)
|
||||||
|
|
||||||
|
def make_connection(self, host):
|
||||||
|
if self._connection and host == self._connection[0]:
|
||||||
|
return self._connection[1]
|
||||||
|
|
||||||
|
chost, self._extra_headers, x509 = self.get_host_info(host)
|
||||||
|
|
||||||
|
if self.secure:
|
||||||
|
try:
|
||||||
|
self._connection = host, httplib.HTTPSConnection(chost, None, **(x509 or {}))
|
||||||
|
except AttributeError:
|
||||||
|
raise NotImplementedError(
|
||||||
|
"your version of httplib doesn't support HTTPS"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._connection = host, httplib.HTTPConnection(chost)
|
||||||
|
|
||||||
|
return self._connection[1]
|
||||||
|
|
||||||
|
|
||||||
def single_request(self, host, handler, request_body, verbose=0):
|
def single_request(self, host, handler, request_body, verbose=0):
|
||||||
# issue XML-RPC request
|
# issue XML-RPC request
|
||||||
|
|||||||
Reference in New Issue
Block a user