Skip to content

Commit

Permalink
#73 405 method not allowed on put/post/delete request methods
Browse files Browse the repository at this point in the history
  • Loading branch information
roefem committed Jun 2, 2022
1 parent fc99fc7 commit 0c64dad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,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
11 changes: 8 additions & 3 deletions urihandler/views.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from pyramid.httpexceptions import HTTPMethodNotAllowed
from pyramid.view import view_config

from pyramid.httpexceptions import (
HTTPSeeOther,
HTTPBadRequest,
HTTPNotFound,
HTTPNotModified
HTTPNotFound
)

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 @@ -19,6 +19,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 0c64dad

Please sign in to comment.