diff --git a/docs/source/tour.rst b/docs/source/tour.rst index 2f94d20..89a495f 100644 --- a/docs/source/tour.rst +++ b/docs/source/tour.rst @@ -159,7 +159,7 @@ You can easily read a Request's session data, that can be trusted to have origin **Note**: if you are using this in production, you should pass the ``secret_key`` argument to ``API(...)``:: - api = responder.API(secret_key=os.environ['SECRET_KEY'] + api = responder.API(secret_key=os.environ['SECRET_KEY']) Using Requests Test Client -------------------------- @@ -182,7 +182,7 @@ Here's an example of a test (written with pytest):: resp.text = hello r = api.requests.get(url=api.url_for(some_view)) - assert r.text = hello + assert r.text == hello HSTS (Redirect to HTTPS) ------------------------ diff --git a/responder/api.py b/responder/api.py index a50bb73..5f04dca 100644 --- a/responder/api.py +++ b/responder/api.py @@ -201,7 +201,6 @@ class API: return route def _prepare_cookies(self, resp): - # print(resp.cookies) if resp.cookies: header = " ".join([f"{k}={v}" for k, v in resp.cookies.items()]) resp.headers["Set-Cookie"] = header @@ -230,7 +229,6 @@ class API: # Create the response object. cont = False - if route: if not route.uses_websocket: resp = models.Response(req=req, formats=self.formats) @@ -292,7 +290,6 @@ class API: else: resp = models.Response(req=req, formats=self.formats) self.default_response(req, resp, notfound=True) - self.default_response(req, resp) self._prepare_session(resp) @@ -328,6 +325,7 @@ class API: if default: self.default_endpoint = endpoint + # Can we remove it ? try: if callable(endpoint): endpoint.is_routed = True @@ -335,7 +333,7 @@ class API: pass self.routes[route] = Route(route, endpoint, websocket=websocket) - # TODO: A better datastructer or sort it once the app is loaded + # TODO: A better data structure or sort it once the app is loaded self.routes = dict( sorted(self.routes.items(), key=lambda item: item[1]._weight()) ) @@ -356,6 +354,7 @@ class API: def static_response(self, req, resp): index = (self.static_dir / "index.html").resolve() + resp.content = "" if os.path.exists(index): with open(index, "r") as f: resp.text = f.read() diff --git a/responder/routes.py b/responder/routes.py index 7e3eb81..a88d878 100644 --- a/responder/routes.py +++ b/responder/routes.py @@ -72,9 +72,10 @@ class Route: @property def is_class_based(self): return hasattr(self.endpoint, "__class__") - - @property + + @property def is_function(self): + # TODO: Should we remove is_routed ? routed = hasattr(self.endpoint, "is_routed") code = hasattr(self.endpoint, "__code__") kwdefaults = hasattr(self.endpoint, "__kwdefaults__")