Support only https_proxy.

This commit is contained in:
Arun Prakash Jana 2016-11-18 20:04:37 +05:30
parent 190097fe53
commit 1aee1232f7
No known key found for this signature in database
GPG Key ID: A75979F35C080412
3 changed files with 15 additions and 36 deletions

View File

@ -239,6 +239,7 @@ Shell completion scripts for Bash, Fish and Zsh can be found in respective subdi
- --stag : search bookmarks by a tag, or show all tags alphabetically (if no arguments).
- Search results are indexed serially. This index is different from actual database index of a bookmark record which is shown in bold within `[]` after the URL.
- **Encryption** is optional and manual. AES256 algorithm is used. To use encryption, the database file should be unlocked (-k) before using buku and locked (-l) afterwards. Between these 2 operations, the database file lies unencrypted on the disk, and NOT in memory. Also, note that the database file is *unencrypted on creation*.
- **Proxy** support: environment variable *https_proxy*, if defined, is used to tunnel data for both http and https connections. The supported format is `http[s]://proxyhost:proxyport/`.
## GUI integration

16
buku.1
View File

@ -57,6 +57,8 @@ Bookmarks with immutable titles are listed with bold '(L)' after the URL.
- Search results are indexed serially. This index is different from actual database index of a bookmark record which is shown in bold within '[]' after the URL.
.PP
\fIEncryption\fR is optional and manual. AES256 algorithm is used. To use encryption, the database file should be unlocked (-k) before using buku and locked (-l) afterwards. Between these 2 operations, the database file lies unencrypted on the disk, and NOT in memory. Also, note that the database file is \fBunencrypted on creation\fR.
.PP
\fIProxy\fR support: refer to the \fBENVIRONMENT\fR section.
.SH GENERAL OPTIONS
.TP
.BI \-a " " \--add " URL [tag, ...]"
@ -223,19 +225,11 @@ Exit buku.
Overrides the default browser. Ref:
.I http://docs.python.org/library/webbrowser.html
.TP
.BR http_proxy ", " HTTP_PROXY ", " https_proxy " or " HTTPS_PROXY"
.BI https_proxy
If defined, will be used to access http and https resources through the configured proxy. Supported format:
If defined, will be used to access http and https resources through the configured proxy.
For https requests, if https proxy is not defined but http is, the latter will be used
instead.
http[s]://proxyhost:proxyport/
They should be in the following format:
http[s]://proxyhost:proxyport
Buku uses urllib3 for proxy support, but that library doesn't support authenticated
proxies. So, if that's your need, you should use a local intermediate proxy, such as
cntlm, TinyProxy or Polipo.
.SH EXAMPLES
.PP
.IP 1. 4

32
buku.py
View File

@ -1492,35 +1492,19 @@ def get_page_title(resp):
return htmlparser.parsed_title
def create_poolmanager(url):
'''Creates a pool manager with proxy support, if needed.
def get_PoolManager():
'''Creates a pool manager with proxy support, if applicable
Checks to see if there are proxy variables defined and creates
a ProxyManager. If not, creates a PoolManager.
:return: ProxyManager if https_proxy is defined, else PoolManager.
'''
# Check if http_proxy or HTTP_PROXY is defined
http_proxy = os.environ.get('http_proxy')
if not http_proxy:
http_proxy = os.environ.get('HTTP_PROXY')
# Check if https_proxy or HTTPS_PROXY is defined
https_proxy = os.environ.get('https_proxy')
if not https_proxy:
https_proxy = os.environ.get('HTTPS_PROXY')
print(https_proxy)
# If not, falls back to http_proxy, which is more common.
if not https_proxy:
https_proxy = http_proxy
if https_proxy:
return urllib3.ProxyManager(https_proxy)
# Create a pool manager with or without proxy support as needed.
if url.startswith('http://') and http_proxy:
manager = urllib3.ProxyManager(http_proxy)
elif url.startswith('https://') and https_proxy:
manager = urllib3.ProxyManager(https_proxy)
else:
manager = urllib3.PoolManager()
return manager;
return urllib3.PoolManager()
def network_handler(url):
@ -1544,7 +1528,7 @@ def network_handler(url):
if not http_handler:
urllib3.disable_warnings()
http_handler = create_poolmanager(url)
http_handler = get_PoolManager()
try:
while True: