Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
e266f25c
Kaydet (Commit)
e266f25c
authored
May 24, 2009
tarafından
Senthil Kumaran
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed Issue1424152, urllib2 fails with HTTPS over Proxy.
üst
655d8354
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
3 deletions
+66
-3
httplib.rst
Doc/library/httplib.rst
+6
-0
httplib.py
Lib/httplib.py
+29
-0
test_urllib2.py
Lib/test/test_urllib2.py
+15
-0
urllib2.py
Lib/urllib2.py
+13
-3
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/httplib.rst
Dosyayı görüntüle @
e266f25c
...
...
@@ -428,6 +428,12 @@ HTTPConnection Objects
debug level is ``0``, meaning no debugging output is printed.
.. method:: HTTPConnection.set_tunnel(host,port=None)
Set the host and the port for HTTP Connect Tunnelling. Normally used when
it is required to do HTTPS Conection through a proxy server.
.. method:: HTTPConnection.connect()
Connect to the server specified when the object was created.
...
...
Lib/httplib.py
Dosyayı görüntüle @
e266f25c
...
...
@@ -662,11 +662,18 @@ class HTTPConnection:
self
.
__response
=
None
self
.
__state
=
_CS_IDLE
self
.
_method
=
None
self
.
_tunnel_host
=
None
self
.
_tunnel_port
=
None
self
.
_set_hostport
(
host
,
port
)
if
strict
is
not
None
:
self
.
strict
=
strict
def
set_tunnel
(
self
,
host
,
port
=
None
):
""" Sets up the host and the port for the HTTP CONNECT Tunnelling."""
self
.
_tunnel_host
=
host
self
.
_tunnel_port
=
port
def
_set_hostport
(
self
,
host
,
port
):
if
port
is
None
:
i
=
host
.
rfind
(
':'
)
...
...
@@ -687,11 +694,30 @@ class HTTPConnection:
def
set_debuglevel
(
self
,
level
):
self
.
debuglevel
=
level
def
_tunnel
(
self
):
self
.
_set_hostport
(
self
.
_tunnel_host
,
self
.
_tunnel_port
)
self
.
send
(
"CONNECT
%
s:
%
d HTTP/1.0
\r\n\r\n
"
%
(
self
.
host
,
self
.
port
))
response
=
self
.
response_class
(
self
.
sock
,
strict
=
self
.
strict
,
method
=
self
.
_method
)
(
version
,
code
,
message
)
=
response
.
_read_status
()
if
code
!=
200
:
self
.
close
()
raise
socket
.
error
,
"Tunnel connection failed:
%
d
%
s"
%
(
code
,
message
.
strip
())
while
True
:
line
=
response
.
fp
.
readline
()
if
line
==
'
\r\n
'
:
break
def
connect
(
self
):
"""Connect to the host and port specified in __init__."""
self
.
sock
=
socket
.
create_connection
((
self
.
host
,
self
.
port
),
self
.
timeout
)
if
self
.
_tunnel_host
:
self
.
_tunnel
()
def
close
(
self
):
"""Close the connection to the HTTP server."""
if
self
.
sock
:
...
...
@@ -1101,6 +1127,9 @@ else:
"Connect to a host on a given (SSL) port."
sock
=
socket
.
create_connection
((
self
.
host
,
self
.
port
),
self
.
timeout
)
if
self
.
_tunnel_host
:
self
.
sock
=
sock
self
.
_tunnel
()
self
.
sock
=
ssl
.
wrap_socket
(
sock
,
self
.
key_file
,
self
.
cert_file
)
__all__
.
append
(
"HTTPSConnection"
)
...
...
Lib/test/test_urllib2.py
Dosyayı görüntüle @
e266f25c
...
...
@@ -939,6 +939,21 @@ class HandlerTests(unittest.TestCase):
self
.
assertEqual
([(
handlers
[
0
],
"http_open"
)],
[
tup
[
0
:
2
]
for
tup
in
o
.
calls
])
def
test_proxy_https
(
self
):
o
=
OpenerDirector
()
ph
=
urllib2
.
ProxyHandler
(
dict
(
https
=
'proxy.example.com:3128'
))
o
.
add_handler
(
ph
)
meth_spec
=
[
[(
"https_open"
,
"return response"
)]
]
handlers
=
add_ordered_mock_handlers
(
o
,
meth_spec
)
req
=
Request
(
"https://www.example.com/"
)
self
.
assertEqual
(
req
.
get_host
(),
"www.example.com"
)
r
=
o
.
open
(
req
)
self
.
assertEqual
(
req
.
get_host
(),
"proxy.example.com:3128"
)
self
.
assertEqual
([(
handlers
[
0
],
"https_open"
)],
[
tup
[
0
:
2
]
for
tup
in
o
.
calls
])
def
test_basic_auth
(
self
,
quote_char
=
'"'
):
opener
=
OpenerDirector
()
password_manager
=
MockPasswordManager
()
...
...
Lib/urllib2.py
Dosyayı görüntüle @
e266f25c
...
...
@@ -192,6 +192,7 @@ class Request:
# self.__r_type is what's left after doing the splittype
self
.
host
=
None
self
.
port
=
None
self
.
_tunnel_host
=
None
self
.
data
=
data
self
.
headers
=
{}
for
key
,
value
in
headers
.
items
():
...
...
@@ -252,8 +253,13 @@ class Request:
return
self
.
__r_host
def
set_proxy
(
self
,
host
,
type
):
self
.
host
,
self
.
type
=
host
,
type
self
.
__r_host
=
self
.
__original
if
self
.
type
==
'https'
and
not
self
.
_tunnel_host
:
self
.
_tunnel_host
=
self
.
host
else
:
self
.
type
=
type
self
.
__r_host
=
self
.
__original
self
.
host
=
host
def
has_proxy
(
self
):
return
self
.
__r_host
==
self
.
__original
...
...
@@ -700,7 +706,7 @@ class ProxyHandler(BaseHandler):
req
.
add_header
(
'Proxy-authorization'
,
'Basic '
+
creds
)
hostport
=
unquote
(
hostport
)
req
.
set_proxy
(
hostport
,
proxy_type
)
if
orig_type
==
proxy_type
:
if
orig_type
==
proxy_type
or
orig_type
==
'https'
:
# let other handlers take care of it
return
None
else
:
...
...
@@ -1098,6 +1104,10 @@ class AbstractHTTPHandler(BaseHandler):
headers
[
"Connection"
]
=
"close"
headers
=
dict
(
(
name
.
title
(),
val
)
for
name
,
val
in
headers
.
items
())
if
req
.
_tunnel_host
:
h
.
set_tunnel
(
req
.
_tunnel_host
)
try
:
h
.
request
(
req
.
get_method
(),
req
.
get_selector
(),
req
.
data
,
headers
)
try
:
...
...
Misc/NEWS
Dosyayı görüntüle @
e266f25c
...
...
@@ -302,6 +302,9 @@ Core and Builtins
Library
-------
- Issue #1424152: Fix for httplib, urllib2 to support SSL while working through
proxy. Original patch by Christopher Li, changes made by Senthil Kumaran.
- Issue #1983: Fix functions taking or returning a process identifier to use
the dedicated C type ``pid_t`` instead of a C ``int``. Some platforms have
a process identifier type wider than the standard C integer type.
...
...
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