Skip to content

Commit 358bc56

Browse files
committed
Add support for authenticated proxies
1 parent 639edbe commit 358bc56

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

.travis.s3cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ preserve_attrs = True
4949
progress_meter = True
5050
proxy_host =
5151
proxy_port = 0
52+
proxy_username =
53+
proxy_password =
5254
put_continue = False
5355
recursive = False
5456
recv_chunk = 65536

S3/Config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class Config(object):
153153
acl_revokes = []
154154
proxy_host = u""
155155
proxy_port = 3128
156+
proxy_username = u""
157+
proxy_password = u""
156158
encrypt = False
157159
dry_run = False
158160
add_encoding_exts = u""

S3/ConnMan.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .Custom_httplib27 import httplib
1616
import ssl
1717

18+
from base64 import b64encode
1819
from logging import debug
1920
from threading import Semaphore
2021
from time import time
@@ -229,11 +230,15 @@ def __init__(self, id, hostname, ssl, cfg):
229230
self.c = httplib.HTTPConnection(self.hostname, self.port)
230231
debug(u'non-proxied HTTPConnection(%s, %s)', self.hostname, self.port)
231232
else:
233+
headers = {}
234+
if cfg.proxy_username and cfg.proxy_password:
235+
headers['Proxy-Authorization'] = 'Basic ' + \
236+
b64encode(('%s:%s' % (cfg.proxy_username, cfg.proxy_password)).encode('utf-8')).decode('ascii')
232237
if ssl:
233238
self.c = http_connection._https_connection(cfg.proxy_host, cfg.proxy_port)
234239
debug(u'proxied HTTPSConnection(%s, %s)', cfg.proxy_host, cfg.proxy_port)
235240
port = self.port and self.port or 443
236-
self.c.set_tunnel(self.hostname, port)
241+
self.c.set_tunnel(self.hostname, port, headers)
237242
debug(u'tunnel to %s, %s', self.hostname, port)
238243
else:
239244
self.c = httplib.HTTPConnection(cfg.proxy_host, cfg.proxy_port)

0 commit comments

Comments
 (0)