mirror of
https://github.com/kennethreitz/responder.git
synced 2026-06-05 23:00:17 +00:00
updates to redirects
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
- Kenneth Reitz (primary)
|
||||
- Tom Christie
|
||||
- Bruno Oliveira
|
||||
- serhii73
|
||||
|
||||
@@ -12,7 +12,7 @@ def hello_world():
|
||||
return "Hello, World from flask!"
|
||||
|
||||
|
||||
api = responder.API()
|
||||
api = responder.API(enable_hsts=True)
|
||||
api.mount("/hello", app)
|
||||
|
||||
|
||||
@@ -40,7 +40,6 @@ schema = graphene.Schema(query=Query)
|
||||
# Alerntatively,
|
||||
api.add_route("/graph", schema, graphiql=True)
|
||||
|
||||
|
||||
print(
|
||||
api.session()
|
||||
.get(
|
||||
|
||||
+7
-2
@@ -96,6 +96,11 @@ class API:
|
||||
route = self.path_matches_route(req.path)
|
||||
resp = models.Response(req=req)
|
||||
|
||||
if self.enable_hsts:
|
||||
if req.url.startswith("http://"):
|
||||
url = req.url.replace("http://", "https://", 1)
|
||||
self.redirect(resp, location=url)
|
||||
|
||||
if route:
|
||||
try:
|
||||
params = self.routes[route].incoming_matches(req.path)
|
||||
@@ -149,8 +154,8 @@ class API:
|
||||
resp.status_code = HTTP_404
|
||||
resp.text = "Not found."
|
||||
|
||||
def redirect(self, location, *, status_code=status_codes.HTTP_301):
|
||||
rep.status_code = status_code
|
||||
def redirect(self, resp, location, *, status_code=status_codes.HTTP_301):
|
||||
resp.status_code = status_code
|
||||
resp.text = f"Redirecting to: {location}"
|
||||
resp.headers.update({"Location": location})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user