comparison src/server/server.py @ 867:12d0e7bd0dd1

server: fixed encoding issues on url redirection
author Goffi <goffi@goffi.org>
date Fri, 26 Feb 2016 19:26:29 +0100
parents 782ba105f5c7
children fa7703642c0e
comparison
equal deleted inserted replaced
866:782ba105f5c7 867:12d0e7bd0dd1
150 elif new_url.scheme in ('', 'http', 'https'): 150 elif new_url.scheme in ('', 'http', 'https'):
151 # direct redirection 151 # direct redirection
152 if new_url.netloc: 152 if new_url.netloc:
153 raise NotImplementedError(u"netloc ({netloc}) is not implemented yet for url_redirections_dict, it is not possible to redirect to an external website".format( 153 raise NotImplementedError(u"netloc ({netloc}) is not implemented yet for url_redirections_dict, it is not possible to redirect to an external website".format(
154 netloc = new_url.netloc)) 154 netloc = new_url.netloc))
155 location = urlparse.urlunsplit(('', '', new_url.path, new_url.query, new_url.fragment)) 155 location = urlparse.urlunsplit(('', '', new_url.path, new_url.query, new_url.fragment)).decode('utf-8')
156 request_data = self._getRequestData(location) 156 request_data = self._getRequestData(location)
157 else: 157 else:
158 raise NotImplementedError(u"{scheme}: scheme is not managed for url_redirections_dict".format(scheme=new_url.scheme)) 158 raise NotImplementedError(u"{scheme}: scheme is not managed for url_redirections_dict".format(scheme=new_url.scheme))
159 self.redirections[old] = request_data 159 self.redirections[old] = request_data
160 if not old: 160 if not old:
215 request._redirected 215 request._redirected
216 except AttributeError: 216 except AttributeError:
217 pass 217 pass
218 else: 218 else:
219 log.warning(D_(u"recursive redirection, please fix this URL:\n{old} ==> {new}").format( 219 log.warning(D_(u"recursive redirection, please fix this URL:\n{old} ==> {new}").format(
220 old=request.uri, 220 old=request.uri.decode('utf-8'),
221 new=uri, 221 new=uri.decode('utf-8'),
222 )) 222 ))
223 return web_resource.NoResource() 223 return web_resource.NoResource()
224 log.debug(u"Redirecting URL {old} to {new}".format( 224 log.debug(u"Redirecting URL {old} to {new}".format(
225 old=request.uri, 225 old=request.uri.decode('utf-8'),
226 new=uri, 226 new=uri.decode('utf-8'),
227 )) 227 ))
228 # we change the request to reflect the new url 228 # we change the request to reflect the new url
229 request._redirected = True # here to avoid recursive redirections 229 request._redirected = True # here to avoid recursive redirections
230 request.postpath = path_list[1:] 230 request.postpath = path_list[1:]
231 request.uri = uri 231 request.uri = uri