kopia lustrzana https://github.com/cirospaciari/socketify.py
added redirect
rodzic
fdef1bbb2a
commit
c860562e2d
|
@ -326,7 +326,14 @@ class AppResponse:
|
|||
if self._ptr == ffi.NULL:
|
||||
self._ptr = ffi.new_handle(self)
|
||||
lib.uws_res_on_aborted(self.SSL, self.res, uws_generic_abord_handler, self._ptr)
|
||||
|
||||
|
||||
def redirect(self, location, status_code=302):
|
||||
if not isinstance(location, str):
|
||||
raise RuntimeError("Location must be an string")
|
||||
self.write_status(status_code)
|
||||
self.write_header("Location", location)
|
||||
self.end_without_body()
|
||||
|
||||
def end(self, message, end_connection=False):
|
||||
if not self.aborted:
|
||||
if isinstance(message, str):
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
aiohttp
|
||||
redis
|
||||
redis
|
||||
git+https://github.com/cirospaciari/socketify.py.git@main#socketify --global-option="build_ext"
|
|
@ -56,6 +56,15 @@ def send_in_parts(res, req):
|
|||
res.write("messages")
|
||||
res.end(" in parts!")
|
||||
|
||||
|
||||
def redirect(res, req):
|
||||
#status code is optional default is 302
|
||||
res.redirect("/redirected", 302)
|
||||
|
||||
def redirected(res, req):
|
||||
res.end("You got redirected to here :D")
|
||||
|
||||
|
||||
def not_found(res, req):
|
||||
res.write_status(404).end("Not Found")
|
||||
|
||||
|
@ -69,6 +78,8 @@ app.get("/json", json)
|
|||
app.get("/sleepy", sleepy_json)
|
||||
app.get("/custom_header", custom_header)
|
||||
app.get("/send_in_parts", send_in_parts)
|
||||
app.get("/redirect", redirect)
|
||||
app.get("/redirected", redirected)
|
||||
# Wildcard at last always :)
|
||||
app.any("/*", not_found)
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue