-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PUT does not work. Always 404 #450
Comments
I'll take a look at it. NOTE: The information in this e-mail is confidential, being solely for the addressee named above. If you read this message and not the intended recipient, please note that it is completely forbidden any use, disclosure, distribution and / or duplication of this communication without the consent of the sender. If you have received this message in error, please notify us immediately by electronic mail and its elimination. On Fri, Oct 2, 2015 at 6:16 PM, Vince Yuan notifications@github.com
|
@javierprovecho Thanks. I override http form method using martini-contrib/method. I am not sure this way is correct. I searched but did not find an example of overriding method for gin. (I am using http form and add something like this
DELETE has the same problem too. If I use router.POST for a DELETE form request, gin recognizes the request as a DELETE but handled it with a POST handler without errors. If I use router.DELETE for a DELETE form request, it says 404. |
@vinceyuan hey, this bad behaviour is because how the router works, not because PUT or DELETE doesn't work. Please avoid using parameters between static path. We will try to make this more friendly, but understand this is for speed and performance. EDIT: I tried both PUT and DELETE with a standard path in develop and master, and it didn't gave me any problem. |
@jasonrhansen Thanks for the response. I made a simple app to reproduce this problem. You can copy into a file and run it. There are just 2 routes
You can see
If I change the code
As I mentioned above, I am not sure my way of overriding method is correct. If it is wrong, could you please show me how to do it correctly? It's not urgent for me, because I can just use POST. But I think somebody else may really need PUT/DELETE. Thanks! |
Hey @vinceyuan The requests are handled correctly when sent through postman or any other api testing tool. I'm sure curl would also give you success on both, get and put. So yes, your code is fine, just the way you use it is not 😄 Send the form from JS and I'm sure it will work. |
@nazwa, probably html forms in Chrome don't allow to do this. If you (@vinceyuan) need to send a PUT request, I suggest using a javascript framework such as angularjs, to archive maximum compatibility between browsers. of course it depends on the requisites of your application. NOTE: The information in this e-mail is confidential, being solely for the addressee named above. If you read this message and not the intended recipient, please note that it is completely forbidden any use, disclosure, distribution and / or duplication of this communication without the consent of the sender. If you have received this message in error, please notify us immediately by electronic mail and its elimination. On Wed, Oct 7, 2015 at 8:33 PM, nazwa notifications@github.com wrote:
|
thank you @nazwa by the way for your research! NOTE: The information in this e-mail is confidential, being solely for the addressee named above. If you read this message and not the intended recipient, please note that it is completely forbidden any use, disclosure, distribution and / or duplication of this communication without the consent of the sender. If you have received this message in error, please notify us immediately by electronic mail and its elimination. On Wed, Oct 7, 2015 at 8:33 PM, nazwa notifications@github.com wrote:
|
@javierprovecho no problem! We use gin for everything, so this is the least I can do in return 😄 |
@nazwa @javierprovecho None of browsers support PUT in form. That's why we add a hidden input
When the server receives a POST request and the form data contains "_method=PUT", it should treat it as a PUT request. We call it overriding. I am using martini-contrib/method to override post method. I searched but don't find an example of overriding post method in gin. |
Och haha, ok. To me this sounds like an art for the sake of art but what do I know. And i'm almost sure it won't work with gin, as the route is determined before middleware, so if requests comes in as post, it is treated as post. Workaround? Use the 'No method' handler and trigger the appropriate route handler manually, but again, not sure what's the value here. |
@vinceyuan I suggest using |
I defined
router.PUT("/admin/sourcesentences/:id/update", routes.UpdateSourceSentence)
When the web app runs, it prints
[GIN-debug] PUT /admin/sourcesentences/:id/update --> myproject/routes.UpdateSourceSentence (4 handlers)
.But when I really send a PUT request via http form (I override POST), I always get 404
[GIN] 2015/10/02 - 23:03:36 | 404 | 89.501µs | [::1]:56720 | PUT /admin/sourcesentences/40/update
At last, I have to use POST.
The text was updated successfully, but these errors were encountered: