commit/galaxy-central: davebgx: Additional fixes for urllib2's 3xx redirects not handling POST requests. This changeset handles httpd proxies that redirect to a secure port before delivering the request to Paste.
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/24c5a89db263/ Changeset: 24c5a89db263 User: davebgx Date: 2014-06-10 17:11:32 Summary: Additional fixes for urllib2's 3xx redirects not handling POST requests. This changeset handles httpd proxies that redirect to a secure port before delivering the request to Paste. Affected #: 1 file diff -r 47e32138de3d0a9debf25cb6b59c967b647af84e -r 24c5a89db2634fcd5339205164f64e3d7a396003 lib/tool_shed/scripts/api/common.py --- a/lib/tool_shed/scripts/api/common.py +++ b/lib/tool_shed/scripts/api/common.py @@ -11,13 +11,25 @@ from tool_shed.util import common_util from tool_shed.util import hg_util + +class HTTPRedirectWithDataHandler( urllib2.HTTPRedirectHandler ): + + def redirect_request( self, request, fp, code, msg, headers, newurl ): + request_method = request.get_method() + if ( code in ( 301, 302, 303, 307 ) and request_method in ( "GET", "HEAD", "POST", "PUT", "DELETE" ) ): + newurl = newurl.replace( ' ', '%20' ) + return urllib2.Request( newurl, + data=request.data, + headers=request.headers, + origin_req_host=request.get_origin_req_host(), + unverifiable=True ) + else: + urllib2.HTTPRedirectHandler.redirect_request( request, fp, code, msg, headers, newurl ) + def build_request_with_data( url, data, api_key, method ): """Build a request with the received method.""" - protocol = common_util.get_protocol_from_tool_shed_url( url ) - if protocol == 'http': - opener = urllib2.build_opener( urllib2.HTTPHandler ) - elif protocol == 'https': - opener = urllib2.build_opener( urllib2.HTTPSHandler ) + opener = urllib2.build_opener( HTTPRedirectWithDataHandler ) + urllib2.install_opener( opener ) url = make_url( url, api_key=api_key, args=None ) request = urllib2.Request( url, headers={ 'Content-Type': 'application/json' }, data=json.dumps( data ) ) request_method = request.get_method() Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org