def _api_index(self, stream, request, query): ''' Redirect either to /index.html or /privacy.html depending on whether the user has already set privacy permissions or not ''' response = Message() if not privacy.allowed_to_run(): response.compose_redirect(stream, '/privacy.html') else: response.compose_redirect(stream, '/index.html') stream.send_response(request, response)
def _api_index(self, stream, request, query): ''' Redirect either to /index.html or /privacy.html depending on whether the user has already set privacy permissions or not ''' response = Message() if (not utils.intify(CONFIG['privacy.informed']) or not utils.intify(CONFIG['privacy.can_collect'])): response.compose_redirect(stream, '/privacy.html') else: response.compose_redirect(stream, '/index.html') stream.send_response(request, response)
def process_request(self, stream, request): ''' Process a request and generate the response ''' response = Message() if not request.uri.startswith("/"): response.compose(code="403", reason="Forbidden", body="403 Forbidden") stream.send_response(request, response) return for prefix, child in self.childs.items(): if request.uri.startswith(prefix): child.process_request(stream, request) return rootdir = self.conf.get("http.server.rootdir", "") if not rootdir: response.compose(code="403", reason="Forbidden", body="403 Forbidden") stream.send_response(request, response) return if request.uri == "/": response.compose_redirect(stream, "/api/index") stream.send_response(request, response) return if '?' in request.uri: request_uri = request.uri.split('?')[0] else: request_uri = request.uri fullpath = utils_path.append(rootdir, request_uri, True) if not fullpath: response.compose(code="403", reason="Forbidden", body="403 Forbidden") stream.send_response(request, response) return try: filep = open(fullpath, "rb") except (IOError, OSError): logging.error("HTTP: Not Found: %s (WWWDIR: %s)", fullpath, rootdir) response.compose(code="404", reason="Not Found", body="404 Not Found") stream.send_response(request, response) return if self.conf.get("http.server.mime", True): mimetype, encoding = mimetypes.guess_type(fullpath) # Do not attempt SSI if the resource is, say, gzipped if not encoding: if mimetype == "text/html": ssi = self.conf.get("http.server.ssi", False) if ssi: body = ssi_replace(rootdir, filep) filep = StringIO.StringIO(body) #XXX Do we need to enforce the charset? if mimetype in ("text/html", "application/x-javascript"): mimetype += "; charset=UTF-8" else: response["content-encoding"] = encoding else: mimetype = "text/plain" response.compose(code="200", reason="Ok", body=filep, mimetype=mimetype) if request.method == "HEAD": utils.safe_seek(filep, 0, os.SEEK_END) stream.send_response(request, response)