From: Naoki Kambe Date: Mon, 15 Oct 2012 12:07:10 +0000 (+0900) Subject: [2298] modify handling the accepted URI X-Git-Tag: trac2487_base~1^2~26^2~24 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=547c50fd0124cffc41407eef14d64ac8e8e90803;p=thirdparty%2Fkea.git [2298] modify handling the accepted URI - Do not return a dynamic page when being requested XSD or XSL. So pass nothing to xsd_handler() or xsl_handler(). Pass path in URI to xml_handler(). - XML_URL_PATH is handled as a directory. When XML_URL_PATH which doesn't ends with '/' is requested, the request is redirected to XML_URL_PATH + '/'. --- diff --git a/src/bin/stats/stats_httpd.py.in b/src/bin/stats/stats_httpd.py.in index 17560e7dd5..7ca923d4d2 100644 --- a/src/bin/stats/stats_httpd.py.in +++ b/src/bin/stats/stats_httpd.py.in @@ -121,31 +121,25 @@ class HttpHandler(http.server.BaseHTTPRequestHandler): req_path = self.path req_path = urllib.parse.urlsplit(req_path).path req_path = urllib.parse.unquote(req_path) - req_path = os.path.normpath(req_path) - path_dirs = req_path.split('/') - path_dirs = [ d for d in filter(None, path_dirs) ] - req_path = '/'+"/".join(path_dirs) - module_name = None - item_name = None - # in case of /bind10/statistics/xxx/YYY/zzz - if len(path_dirs) >= 5: - item_name = path_dirs[4] - # in case of /bind10/statistics/xxx/YYY ... - if len(path_dirs) >= 4: - module_name = path_dirs[3] - if req_path == '/'.join([XML_URL_PATH] + path_dirs[3:5]): - body = self.server.xml_handler(module_name, item_name) - elif req_path == '/'.join([XSD_URL_PATH] + path_dirs[3:5]): - body = self.server.xsd_handler(module_name, item_name) - elif req_path == '/'.join([XSL_URL_PATH] + path_dirs[3:5]): - body = self.server.xsl_handler(module_name, item_name) + body = None + if req_path.find('%s/' % XML_URL_PATH) == 0: + req_path = os.path.normpath(req_path) + req_path = req_path.lstrip('%s/' % XML_URL_PATH) + path_dirs = req_path.split('/') + path_dirs = [ d for d in filter(None, path_dirs) ] + req_path = '/'.join(path_dirs) + body = self.server.xml_handler(req_path) + elif req_path == XSD_URL_PATH: + body = self.server.xsd_handler() + elif req_path == XSL_URL_PATH: + body = self.server.xsl_handler() else: - if req_path == '/' and 'Host' in self.headers.keys(): - # redirect to XML URL only when requested with '/' + if 'Host' in self.headers.keys() and \ + ( req_path == '/' or req_path == XML_URL_PATH ): + # redirect to XML URL only when requested with '/' or XML_URL_PATH + toloc = "http://%s%s/" % (self.headers.get('Host'), XML_URL_PATH) self.send_response(302) - self.send_header( - "Location", - "http://" + self.headers.get('Host') + XML_URL_PATH) + self.send_header("Location", toloc) self.end_headers() return None else: