Skip to content

Delete Request not including request body #146

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

Closed
prafsoni opened this issue Dec 18, 2019 · 12 comments
Closed

Delete Request not including request body #146

prafsoni opened this issue Dec 18, 2019 · 12 comments
Labels
kind/bug Feature doesn't work as expected.

Comments

@prafsoni
Copy link

I am seeing that even though I create delete Request with body but the request received by server doesn't have the body. Is this not supported ? if so what is the rationale behind it?

@weissi
Copy link
Contributor

weissi commented Dec 18, 2019

CC @artemredkin

@weissi weissi added the kind/bug Feature doesn't work as expected. label Dec 18, 2019
@weissi
Copy link
Contributor

weissi commented Dec 18, 2019

From RFC7231

A payload within a DELETE request message has no defined semantics;
sending a payload body on a DELETE request might cause some existing
implementations to reject the request.

That seems like we do actually comply to the spec because a payload on DELETE has no defined semantics. However, it might be better to pass the body on or to fail the request...

CC @Lukasa

@Lukasa
Copy link
Collaborator

Lukasa commented Dec 18, 2019

"No defined semantics" doesn't mean "cannot have", just means that REST doesn't imply anything about what such a payload means. It's totally fine to have one, it's just up to the server and client to agree on what it means.

The actual bug here is in NIOHTTP1. I captured the TCP stream of such a request in Wireshark, and here's what we sent (I just picked a random body I had lying around in a sample project):

DELETE /delete HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: httpbin.org
Connection: close

grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=ddd

This occurs because NIOHTTP1's sanitizeTransportHeaders is stripping the content-length header that async-http-client set. The switch statement in HTTPMethod.hasRequestBody is overbroad: we should be only forbidding bodies in TRACE. HEAD and DELETE may have bodies, they just have no defined meaning, so they should go in .unlikely. That will fix this issue we see here.

@weissi
Copy link
Contributor

weissi commented Dec 18, 2019

@Lukasa my reading of “no defined semantics” was that server & client can do whatever they want. Therefore I was assuming that not sending it is spec compliant (and so is sending it).
I agree that the spec definitely doesn’t say it must not have a body.

@Lukasa
Copy link
Collaborator

Lukasa commented Dec 18, 2019

Not sending it is spec compliant but not useful, as there are definitely use-cases that require sending it.

@weissi
Copy link
Contributor

weissi commented Dec 18, 2019

Agreed, hence suggesting to either sending it (more useful) or failing it (less useful). I’ll file a NIOHTTP1 bug.

@prafsoni
Copy link
Author

So it had to do purely with swift-nio. This is awesome I really appreciate the fix, as there are scenarios/apis where we require body in delete

Assuming this will be fixed in next patch release of swift-nio And using it in my project will fix it for I will have to wait for async-http-client Release?

@weissi
Copy link
Contributor

weissi commented Dec 18, 2019

@prafsoni once nio is released a swift package update will be enough. You could also add a dependency on the to-be-released NIO version into your own package to force the new version even without swift package update

@prafsoni
Copy link
Author

@weissi Thanks. My project already has NIO dependency so it’s good to know I can get fix sooner. But I think I can wait till nio is released.

@weissi
Copy link
Contributor

weissi commented Dec 21, 2019

@prafsoni should be fixed with NIO 2.12.0. Mind confirming this works?

@prafsoni
Copy link
Author

@weissi it's working :)

@weissi
Copy link
Contributor

weissi commented Dec 23, 2019

Thanks so much, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Feature doesn't work as expected.
Projects
None yet
Development

No branches or pull requests

3 participants