Skip to content

Commit

Permalink
Merge d4216a4 into 4ae0014
Browse files Browse the repository at this point in the history
  • Loading branch information
roefem committed Jul 6, 2022
2 parents 4ae0014 + d4216a4 commit 45faafa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def test_redirect(self, app):
res = app.get("/foobar/18", status=303)
assert res.status == "303 See Other"

def test_redirect_not_allowed(self, app):
res = app.post("/foobar/18", status=405)
assert res.status == "405 Method Not Allowed"

def test_redirect_no_match(self, app):
res = app.get("/test", status=404)
assert res.status == "404 Not Found"
Expand Down
8 changes: 7 additions & 1 deletion urihandler/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pyramid.httpexceptions import HTTPBadRequest
from pyramid.httpexceptions import HTTPMethodNotAllowed
from pyramid.httpexceptions import HTTPNotFound
from pyramid.httpexceptions import HTTPSeeOther
from pyramid.view import view_config

from urihandler.utils import create_version_hash


@view_config(route_name="redirect")
@view_config(route_name="redirect", request_method=("GET", "HEAD", "OPTIONS"))
def redirect(request):
uri = request.host_url + "/" + request.matchdict["uri"]
redirect = request.uri_handler.handle(uri, request)
Expand All @@ -15,6 +16,11 @@ def redirect(request):
return HTTPSeeOther(redirect)


@view_config(route_name="redirect")
def redirect_not_allowed(request):
raise HTTPMethodNotAllowed()


@view_config(route_name="handle")
def handle(request):
uri = request.params.get("uri", None)
Expand Down

0 comments on commit 45faafa

Please sign in to comment.