Closed petrohi closed 5 years ago
What do you mean by empty body? How do you call it?
Like this: :gun.request(pid, "PUT", "/some", [{"content-type", "application/json"}], "", %{})
That's not a bug per se, perhaps the interface is not obvious. If you set content-type but don't set a body you are expected to use the gun:data functions to send that body.
Would probably make sense for body be some atom in this case. But yes--makes sense.
Yes I don't disagree.
Let's keep it open if you don't mind, it'd be good to fix this, or at least error out earlier, at some point.
https://github.com/petrohi/machine_gun/issues/1 is an example real-world issue caused by this.
Also occurs for gun:get/2
.
It's going to be hard to rework this in a backward compatible manner but let's give it a try.
delete/2,3,4
: fin, body has no meaningget/2,3,4
: fin, body has no meaninghead/2,3,4
: fin, body has no meaningoptions/2,3,4
: fin, body has no meaningpatch/3
, post/3
, put/3
: check headers to decide, nofin if content-length/content-type, fin otherwisepatch/4,5
, post/4,5, put/4,5: fin, body is provided as an argumentrequest/4
: check headers to decide, nofin if content-length/content-type, fin otherwiserequest/5,6
: fin, body is provided as an argumentI suggest having two functions instead of request/4,5,6
in the future:
headers/4,5
which sends headers and expects more data to come separatelyrequest/5,6
which sends headers and body and expects no more data to comeThat means that the method-functions can be converted to calling one or the other function depending on whether they expect more data afterwards.
The following can be deprecated and removed in Gun 2.0:
request/4
deprecated in favor of headers/4,5
patch/3
, post/3
and put/3
will always expect a body to follow separately; if one needs to send a PATCH/POST/PUT without a body they can always call the functions request/5,6
I think this can be done without breaking any user code, since the documented behavior will be preserved. Thoughts?
Edited a proposal. Thoughts?
Should this be?
patch/4,5, post/4,5, put/4,5: nofin, body is provided as an argument
No by nofin I mean the data function can be called (the body isn't finished after the request call), while fin sends everything it gets and terminates the request.
Understand now. request/4
with headers check is temporary for compatibility?
Yes until Gun 2.0. request/4
would be removed then and you'd have to call one or the other function to be able to send body or not. So we'd still have the header issue for patch/3
, post/3
, put/3
and request/4
for now but request/4
would be undocumented immediately in favor of the functions headers/4,5
, and it's a lesser problem for the other 3.
So how do i need to deal with this? currently I have an API returning 80K req/min with "" body and no content-length
PS i should mention I'm using machine_gun
I'm currently doing some rework and tbh will probably make it Gun 2.0 and do the breaking changes we need.
That said, I'm not sure you have the right bug, if you do then all you need to do is remove the content-type or ensure you send a final empty data.
Please review 630bd47 which contains the proposed solution for Gun 2.0.
I'll close this meanwhile since I believe this is addressed but feel free to say otherwise or reopen. Thanks!
On subsequent request: