def router_middleware(request, following): path = request.path if path == '/': response = request_html(request) elif path == '/1kb-response': response = request_1kb(request) elif path == '/100kb-response': response = request_100kb(request) elif path == '/1mb-response': response = request_1mb(request) elif path == '/json-response': response = request_json(request) elif path == '/html-response': response = request_html(request) elif path == '/slow-response': response = request_slow(request) elif path == '/db-read': response = request_db_read(request) elif path == '/db-write': response = request_db_write(request) elif path == '/cache-read': response = request_cache_read(request) else: response = not_found() return response
def router_middleware(request, following): path = request.path if path == '/': response = welcome(request) elif path.startswith('/captcha.jpg'): response = captcha_handler(request) else: response = not_found() return response
def router(request, following): match = matcher.match(request.path) if match: # A real router would probably have to get all named params params = match.groupdict() response = hello(request, **params) else: response = wheezy.not_found() return response
def get(self, skip_body=False): route_args = self.route_args path = route_args['path'] assert path abspath = os.path.abspath(os.path.join(self.root, path)) if not abspath.startswith(self.root): return forbidden() if not os.path.exists(abspath): return not_found() if not os.path.isfile(abspath): return forbidden() mime_type, encoding = mimetypes.guess_type(abspath) response = HTTPResponse(mime_type or 'plain/text', encoding) if not skip_body: response.headers.append(HTTP_HEADER_ACCEPT_RANGE_NONE) file = open(abspath, 'rb') try: response.write_bytes(file.read()) finally: file.close() return response
def router_middleware(request, following): path = request.path if path == "/1kb-response": response = request1kb(request) elif path == "/100kb-response": response = request100kb(request) elif path == "/1mb-response": response = request1mb(request) elif path == "/1s-response": response = request1s(request) elif path == "/json-response": response = requestJson(request) elif path == "/html-response": response = requestHtml(request) elif path == "/db-create": response = requestDBcreate(request) elif path == "/db-read": response = requestDBread(request) elif path == "/db-crud": response = requestDBcrud(request) else: response = not_found() return response