307 on a delete for a post request.
See original GitHub issueDescribe the bug
When a delete is made on a post route with a trailing slash the server returns a 307 temporary redirect. I would either expect a 404 not found or a 405 method not allowed.
To Reproduce
Just a unittest to show the case:
from fastapi import FastAPI, Request, Response
from fastapi.testclient import TestClient
app = FastAPI()
@app.post("/bla")
async def bla():
return {}
client = TestClient(app)
def test_read_main():
response = client.delete("/bla/")
print(response.headers)
assert response.status_code == 405
Environment
- OS: all
- FastAPI Version: 0.53.2
- Python Version: 3.8.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
307 Temporary Redirect - HTTP - MDN Web Docs
HTTP 307 Temporary Redirect redirect status response code indicates that the resource requested has been temporarily moved to the URL given ...
Read more >What is the HTTP 307 Temporary Redirect Status Code - Kinsta
The 307 status code indicates that the target resource resides temporarily under a different URI. Find out more with this in-depth guide.
Read more >307 Temporary Redirect: What It Is and How to Fix It
A 307 Temporary Redirect message is an HTTP response status code indicating that the requested resource has been temporarily moved to ...
Read more >How to remove post parameters on temporary redirect (HTTP ...
I have a problem with redirecting requests. I have an incoming GET or POST for http://foo.com/bar?A=b . I redirect it with HTTP 307...
Read more >How to redirect a HTTP put, post or delete requests and keep ...
302 and 307 are temporary redirects, this means that the client should not cache the redirect and should request the original resource next...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just had a look into this. The main
FastAPI
instance has anAPIRouter
.When you create separate
fastapi.routing.APIRouter
instances and then useapp.include_router(...)
, behind the scenes it is actually appending the routes from this router toFastAPI#router
.This should work:
Seems that
redirect_slashes
means “redirect paths without trailing slash to slash”, NOT “redirect trailing slash to no slash”.starlette/routing.py:601
Also, if you are using a FastAPI or Flask backend via a proxy (like in CRA
setupProxy.js
withhttp-proxy-middleware
), then you have some additional work to do as described here: https://github.com/chimurai/http-proxy-middleware/issues/140#issuecomment-611237707Your path has some error. you should use :
response = client.delete("/bla")