Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for authenticated proxies #1129

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for authenticated proxies
  • Loading branch information
mikoim committed Sep 3, 2020
commit 358bc561f4c5d865081493894040b47bd99376fa
2 changes: 2 additions & 0 deletions .travis.s3cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ preserve_attrs = True
progress_meter = True
proxy_host =
proxy_port = 0
proxy_username =
proxy_password =
put_continue = False
recursive = False
recv_chunk = 65536
Expand Down
2 changes: 2 additions & 0 deletions S3/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class Config(object):
acl_revokes = []
proxy_host = u""
proxy_port = 3128
proxy_username = u""
proxy_password = u""
encrypt = False
dry_run = False
add_encoding_exts = u""
Expand Down
7 changes: 6 additions & 1 deletion S3/ConnMan.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .Custom_httplib27 import httplib
import ssl

from base64 import b64encode
from logging import debug
from threading import Semaphore
from time import time
Expand Down Expand Up @@ -229,11 +230,15 @@ def __init__(self, id, hostname, ssl, cfg):
self.c = httplib.HTTPConnection(self.hostname, self.port)
debug(u'non-proxied HTTPConnection(%s, %s)', self.hostname, self.port)
else:
headers = {}
if cfg.proxy_username and cfg.proxy_password:
headers['Proxy-Authorization'] = 'Basic ' + \
b64encode(('%s:%s' % (cfg.proxy_username, cfg.proxy_password)).encode('utf-8')).decode('ascii')
if ssl:
self.c = http_connection._https_connection(cfg.proxy_host, cfg.proxy_port)
debug(u'proxied HTTPSConnection(%s, %s)', cfg.proxy_host, cfg.proxy_port)
port = self.port and self.port or 443
self.c.set_tunnel(self.hostname, port)
self.c.set_tunnel(self.hostname, port, headers)
debug(u'tunnel to %s, %s', self.hostname, port)
else:
self.c = httplib.HTTPConnection(cfg.proxy_host, cfg.proxy_port)
Expand Down