Commit 0614f1a3 authored by Ivan Tyagov's avatar Ivan Tyagov

Use location header (redirect URL) for http codes between 300 and 400 (redirects).

Try to adjust its arguments in only if they are URLs  and point to proxy instance 
(i.e. it should point to remore instance).  


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23573 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 065baacb
...@@ -41,6 +41,7 @@ import xmlrpclib, socket, sys, traceback, urllib, urllib2, base64, cgi ...@@ -41,6 +41,7 @@ import xmlrpclib, socket, sys, traceback, urllib, urllib2, base64, cgi
from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager from AccessControl.SecurityManagement import newSecurityManager, noSecurityManager
import zLOG import zLOG
import cookielib import cookielib
from urlparse import urlparse, urlunparse
# global (RAM) cookie storage # global (RAM) cookie storage
cookiejar = cookielib.CookieJar() cookiejar = cookielib.CookieJar()
...@@ -311,7 +312,7 @@ class WizardTool(BaseTool): ...@@ -311,7 +312,7 @@ class WizardTool(BaseTool):
header_dict['Cookie'] += '%s=%s;' %(cookie.name, cookie.value) header_dict['Cookie'] += '%s=%s;' %(cookie.name, cookie.value)
# XXX: include cookies from local browser (like show/hide tabs) which are set directly # XXX: include cookies from local browser (like show/hide tabs) which are set directly
# by client JavaScript code (i.e. not sent from server) # by client JavaScript code (i.e. not sent from server)
# add HTTP referer (especially useful in Localizer when changing language) # add HTTP referer (especially useful in Localizer when changing language)
header_dict['REFERER'] = self.REQUEST.get('HTTP_REFERER', None) or referer header_dict['REFERER'] = self.REQUEST.get('HTTP_REFERER', None) or referer
request = urllib2.Request(url, data, header_dict) request = urllib2.Request(url, data, header_dict)
...@@ -322,9 +323,17 @@ class WizardTool(BaseTool): ...@@ -322,9 +323,17 @@ class WizardTool(BaseTool):
metadata = f.info() metadata = f.info()
response = self.REQUEST.RESPONSE response = self.REQUEST.RESPONSE
if f.code> 300 and f.code <400: if f.code> 300 and f.code <400:
# ignore 'location' header for redirects from server. If server requires redirect then # adjust return url which my contain proxy URLs as arguments
# redirect it ONLY to root web siteor current location location = metadata.getheader('location')
response['location'] = header_dict['REFERER'] parsed_url = list(urlparse(location))
local_site_url_prefix = urllib.quote('%s/portal_wizard/proxy' \
%self.getPortalObject().absolute_url())
remote_url_parsed = urlparse(self.getServerUrl())
remote_site_url_prefix = '%s://%s/kb' %(remote_url_parsed[0], remote_url_parsed[1])
# fix arguments for returned location URL
parsed_url[4] = parsed_url[4].replace(local_site_url_prefix, remote_site_url_prefix)
response['location'] = urlunparse(parsed_url)
response.setStatus(f.code, f.msg) response.setStatus(f.code, f.msg)
response.setHeader('content-type', metadata.getheader('content-type')) response.setHeader('content-type', metadata.getheader('content-type'))
# FIXME this list should be confirmed with the RFC 2616. # FIXME this list should be confirmed with the RFC 2616.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment