Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vmj-qt
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
vmj-qt
Commits
f8ba1d97
Commit
f8ba1d97
authored
Jul 26, 2010
by
Saul Ibarra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove non-working HTTP proxy code from Google libraries
parent
5728e3ba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
229 deletions
+12
-229
http.py
blink/google/atom/http.py
+2
-87
http_core.py
blink/google/atom/http_core.py
+4
-73
service.py
blink/google/atom/service.py
+6
-69
No files found.
blink/google/atom/http.py
View file @
f8ba1d97
...
...
@@ -205,98 +205,13 @@ class ProxiedHttpClient(HttpClient):
HttpClient.request.
"""
def
_prepare_connection
(
self
,
url
,
headers
):
proxy_auth
=
_get_proxy_auth
()
if
url
.
protocol
==
'https'
:
# destination is https
proxy
=
os
.
environ
.
get
(
'https_proxy'
)
if
proxy
:
# Set any proxy auth headers
if
proxy_auth
:
proxy_auth
=
'Proxy-authorization:
%
s'
%
proxy_auth
# Construct the proxy connect command.
port
=
url
.
port
if
not
port
:
port
=
'443'
proxy_connect
=
'CONNECT
%
s:
%
s HTTP/1.0
\r\n
'
%
(
url
.
host
,
port
)
# Set the user agent to send to the proxy
if
headers
and
'User-Agent'
in
headers
:
user_agent
=
'User-Agent:
%
s
\r\n
'
%
(
headers
[
'User-Agent'
])
else
:
user_agent
=
''
proxy_pieces
=
'
%
s
%
s
%
s
\r\n
'
%
(
proxy_connect
,
proxy_auth
,
user_agent
)
# Find the proxy host and port.
proxy_url
=
atom_url
.
parse_url
(
proxy
)
if
not
proxy_url
.
port
:
proxy_url
.
port
=
'80'
# Connect to the proxy server, very simple recv and error checking
p_sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
p_sock
.
connect
((
proxy_url
.
host
,
int
(
proxy_url
.
port
)))
p_sock
.
sendall
(
proxy_pieces
)
response
=
''
# Wait for the full response.
while
response
.
find
(
"
\r\n\r\n
"
)
==
-
1
:
response
+=
p_sock
.
recv
(
8192
)
p_status
=
response
.
split
()[
1
]
if
p_status
!=
str
(
200
):
raise
ProxyError
(
'Error status=
%
s'
%
str
(
p_status
))
# Trivial setup for ssl socket.
sslobj
=
None
if
ssl_imported
:
sslobj
=
ssl
.
wrap_socket
(
p_sock
,
None
,
None
)
else
:
sock_ssl
=
socket
.
ssl
(
p_sock
,
None
,
None
)
sslobj
=
httplib
.
FakeSocket
(
p_sock
,
sock_ssl
)
# Initalize httplib and replace with the proxy socket.
connection
=
httplib
.
HTTPConnection
(
proxy_url
.
host
)
connection
.
sock
=
sslobj
return
connection
else
:
# The request was HTTPS, but there was no https_proxy set.
return
HttpClient
.
_prepare_connection
(
self
,
url
,
headers
)
else
:
proxy
=
os
.
environ
.
get
(
'http_proxy'
)
if
proxy
:
# Find the proxy host and port.
proxy_url
=
atom_url
.
parse_url
(
proxy
)
if
not
proxy_url
.
port
:
proxy_url
.
port
=
'80'
if
proxy_auth
:
headers
[
'Proxy-Authorization'
]
=
proxy_auth
.
strip
()
return
httplib
.
HTTPConnection
(
proxy_url
.
host
,
int
(
proxy_url
.
port
))
else
:
# The request was HTTP, but there was no http_proxy set.
return
HttpClient
.
_prepare_connection
(
self
,
url
,
headers
)
# XXX: Non working proxy support removed. -Saul
return
HttpClient
.
_prepare_connection
(
self
,
url
,
headers
)
def
_get_access_url
(
self
,
url
):
return
url
.
to_string
()
def
_get_proxy_auth
():
proxy_username
=
os
.
environ
.
get
(
'proxy-username'
)
if
not
proxy_username
:
proxy_username
=
os
.
environ
.
get
(
'proxy_username'
)
proxy_password
=
os
.
environ
.
get
(
'proxy-password'
)
if
not
proxy_password
:
proxy_password
=
os
.
environ
.
get
(
'proxy_password'
)
if
proxy_username
:
user_auth
=
base64
.
encodestring
(
'
%
s:
%
s'
%
(
proxy_username
,
proxy_password
))
return
'Basic
%
s
\r\n
'
%
(
user_auth
.
strip
())
else
:
return
''
def
_send_data_part
(
data
,
connection
):
if
isinstance
(
data
,
types
.
StringTypes
):
connection
.
send
(
data
)
...
...
blink/google/atom/http_core.py
View file @
f8ba1d97
...
...
@@ -521,76 +521,7 @@ class ProxiedHttpClient(HttpClient):
def
_get_connection
(
self
,
uri
,
headers
=
None
):
# Check to see if there are proxy settings required for this request.
proxy
=
None
if
uri
.
scheme
==
'https'
:
proxy
=
os
.
environ
.
get
(
'https_proxy'
)
elif
uri
.
scheme
==
'http'
:
proxy
=
os
.
environ
.
get
(
'http_proxy'
)
if
not
proxy
:
return
HttpClient
.
_get_connection
(
self
,
uri
,
headers
=
headers
)
# Now we have the URL of the appropriate proxy server.
# Get a username and password for the proxy if required.
proxy_auth
=
_get_proxy_auth
()
if
uri
.
scheme
==
'https'
:
if
proxy_auth
:
proxy_auth
=
'Proxy-authorization:
%
s'
%
proxy_auth
# Construct the proxy connect command.
port
=
uri
.
port
if
not
port
:
port
=
443
proxy_connect
=
'CONNECT
%
s:
%
s HTTP/1.0
\r\n
'
%
(
uri
.
host
,
port
)
# Set the user agent to send to the proxy
user_agent
=
''
if
headers
and
'User-Agent'
in
headers
:
user_agent
=
'User-Agent:
%
s
\r\n
'
%
(
headers
[
'User-Agent'
])
proxy_pieces
=
'
%
s
%
s
%
s
\r\n
'
%
(
proxy_connect
,
proxy_auth
,
user_agent
)
# Find the proxy host and port.
proxy_uri
=
Uri
.
parse_uri
(
proxy
)
if
not
proxy_uri
.
port
:
proxy_uri
.
port
=
'80'
# Connect to the proxy server, very simple recv and error checking
p_sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
p_sock
.
connect
((
proxy_uri
.
host
,
int
(
proxy_uri
.
port
)))
p_sock
.
sendall
(
proxy_pieces
)
response
=
''
# Wait for the full response.
while
response
.
find
(
"
\r\n\r\n
"
)
==
-
1
:
response
+=
p_sock
.
recv
(
8192
)
p_status
=
response
.
split
()[
1
]
if
p_status
!=
str
(
200
):
raise
ProxyError
(
'Error status=
%
s'
%
str
(
p_status
))
# Trivial setup for ssl socket.
sslobj
=
None
if
ssl
is
not
None
:
sslobj
=
ssl
.
wrap_socket
(
p_sock
,
None
,
None
)
else
:
sock_ssl
=
socket
.
ssl
(
p_sock
,
None
,
Nonesock_
)
sslobj
=
httplib
.
FakeSocket
(
p_sock
,
sock_ssl
)
# Initalize httplib and replace with the proxy socket.
connection
=
httplib
.
HTTPConnection
(
proxy_uri
.
host
)
connection
.
sock
=
sslobj
return
connection
elif
uri
.
scheme
==
'http'
:
proxy_uri
=
Uri
.
parse_uri
(
proxy
)
if
not
proxy_uri
.
port
:
proxy_uri
.
port
=
'80'
if
proxy_auth
:
headers
[
'Proxy-Authorization'
]
=
proxy_auth
.
strip
()
return
httplib
.
HTTPConnection
(
proxy_uri
.
host
,
int
(
proxy_uri
.
port
))
return
None
def
_get_proxy_auth
():
import
base64
proxy_username
=
os
.
environ
.
get
(
'proxy-username'
)
if
not
proxy_username
:
proxy_username
=
os
.
environ
.
get
(
'proxy_username'
)
proxy_password
=
os
.
environ
.
get
(
'proxy-password'
)
if
not
proxy_password
:
proxy_password
=
os
.
environ
.
get
(
'proxy_password'
)
if
proxy_username
:
user_auth
=
base64
.
b64encode
(
'
%
s:
%
s'
%
(
proxy_username
,
proxy_password
))
return
'Basic
%
s
\r\n
'
%
(
user_auth
.
strip
())
else
:
return
''
# XXX: Non working proxy support removed. -Saul
return
HttpClient
.
_get_connection
(
self
,
uri
,
headers
=
headers
)
blink/google/atom/service.py
View file @
f8ba1d97
...
...
@@ -376,77 +376,14 @@ def PrepareConnection(service, full_uri):
(
server
,
port
,
ssl
,
partial_uri
)
=
ProcessUrl
(
service
,
full_uri
)
if
ssl
:
# destination is https
proxy
=
os
.
environ
.
get
(
'https_proxy'
)
if
proxy
:
(
p_server
,
p_port
,
p_ssl
,
p_uri
)
=
ProcessUrl
(
service
,
proxy
,
True
)
proxy_username
=
os
.
environ
.
get
(
'proxy-username'
)
if
not
proxy_username
:
proxy_username
=
os
.
environ
.
get
(
'proxy_username'
)
proxy_password
=
os
.
environ
.
get
(
'proxy-password'
)
if
not
proxy_password
:
proxy_password
=
os
.
environ
.
get
(
'proxy_password'
)
if
proxy_username
:
user_auth
=
base64
.
encodestring
(
'
%
s:
%
s'
%
(
proxy_username
,
proxy_password
))
proxy_authorization
=
(
'Proxy-authorization: Basic
%
s
\r\n
'
%
(
user_auth
.
strip
()))
else
:
proxy_authorization
=
''
proxy_connect
=
'CONNECT
%
s:
%
s HTTP/1.0
\r\n
'
%
(
server
,
port
)
user_agent
=
'User-Agent:
%
s
\r\n
'
%
(
service
.
additional_headers
[
'User-Agent'
])
proxy_pieces
=
(
proxy_connect
+
proxy_authorization
+
user_agent
+
'
\r\n
'
)
#now connect, very simple recv and error checking
p_sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
p_sock
.
connect
((
p_server
,
p_port
))
p_sock
.
sendall
(
proxy_pieces
)
response
=
''
# Wait for the full response.
while
response
.
find
(
"
\r\n\r\n
"
)
==
-
1
:
response
+=
p_sock
.
recv
(
8192
)
p_status
=
response
.
split
()[
1
]
if
p_status
!=
str
(
200
):
raise
'Error status='
,
str
(
p_status
)
# Trivial setup for ssl socket.
ssl
=
socket
.
ssl
(
p_sock
,
None
,
None
)
fake_sock
=
httplib
.
FakeSocket
(
p_sock
,
ssl
)
# Initalize httplib and replace with the proxy socket.
connection
=
httplib
.
HTTPConnection
(
server
)
connection
.
sock
=
fake_sock
full_uri
=
partial_uri
else
:
connection
=
httplib
.
HTTPSConnection
(
server
,
port
)
full_uri
=
partial_uri
# XXX: Non working proxy support removed. -Saul
connection
=
httplib
.
HTTPSConnection
(
server
,
port
)
full_uri
=
partial_uri
else
:
# destination is http
proxy
=
os
.
environ
.
get
(
'http_proxy'
)
if
proxy
:
(
p_server
,
p_port
,
p_ssl
,
p_uri
)
=
ProcessUrl
(
service
.
server
,
proxy
,
True
)
proxy_username
=
os
.
environ
.
get
(
'proxy-username'
)
if
not
proxy_username
:
proxy_username
=
os
.
environ
.
get
(
'proxy_username'
)
proxy_password
=
os
.
environ
.
get
(
'proxy-password'
)
if
not
proxy_password
:
proxy_password
=
os
.
environ
.
get
(
'proxy_password'
)
if
proxy_username
:
UseBasicAuth
(
service
,
proxy_username
,
proxy_password
,
True
)
connection
=
httplib
.
HTTPConnection
(
p_server
,
p_port
)
if
not
full_uri
.
startswith
(
"http://"
):
if
full_uri
.
startswith
(
"/"
):
full_uri
=
"http://
%
s
%
s"
%
(
service
.
server
,
full_uri
)
else
:
full_uri
=
"http://
%
s/
%
s"
%
(
service
.
server
,
full_uri
)
else
:
connection
=
httplib
.
HTTPConnection
(
server
,
port
)
full_uri
=
partial_uri
# XXX: Non working proxy support removed. -Saul
connection
=
httplib
.
HTTPConnection
(
server
,
port
)
full_uri
=
partial_uri
return
(
connection
,
full_uri
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment