got: The GET method cannot be used with a body
Describe the bug
- Node.js version: 12
- OS & version: Ubuntu
TypeError {
message: 'The `GET` method cannot be used with a body',
}
Object.exports.normalizeRequestArguments (node_modules/got/dist/source/normalize-arguments.js:262:19)
get (node_modules/got/dist/source/request-as-event-emitter.js:39:55)
node_modules/got/dist/source/request-as-event-emitter.js:244:19
I ran into this when upgrading to got@10.0.1.
I realize this is up for debate, but to my best knowledge, a lot of HTTP servers do support GET requests with a body. Elasticsearch, for example, heavily uses this. (They also provide an escape hatch with POST though.)
I don’t think got
should be the limiting factor, given that the underlying modules allow it.
Checklist
- I have read the documentation.
- I have tried my code with the latest version of Node.js and Got.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 28 (3 by maintainers)
I just call this function then get
TypeError: The 'GET' method cannot be used with a body
.ipStack()
is work on v9.6.0, but it throw the error on v10.2.1.Elastic Search requires the use of body with GET. https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html
Just an example where people get creative with their usages of HTTP. I think that a blanket restriction like that is quite weird, when it has been supported for so long by HTTP/1.1.
@nordluf Unfortunately there’s nothing you can do but to switch to POST instead. We understand your frustration, but this is done to make the behavior more reliable according to the RFC.
@kelp404’s example has got some inconsistencies: the
json
option works differently than in v9.6.0, it no longer converts response to JSON.got(...).json()
should be used instead (in this case).Nuance: the RFC doesn’t support it. The RFC also wants you to keep the header size under 2,000 bytes but I’ve seen URLs way longer than that. Should got also disallow those?
@szmarczak Can you link to the RFC and the duplicate issue? We should probably document this more clearly in the readme.
@timdp , Elasticsearch statement about it is the following (emphasis mine):
That does not really matter, though, as Elasticserach is just an example. But looking into the docs, RFC 7237 says that “[it] is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG).”
It points to RFC7231, “Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content”, which contains this excerpt about GET method (emphasis mine):
There is nothing — in the current documentation — that determines that GET bodies should be prohibited, specially when coming from a client library making the request. Therefore, the current behaviour has been determined by
got
, not by any real established standards. I understand the recommendation not to use it (and I agree with it), but blanket prohibition makes it unusable when interacting with systems that chose unorthodox GET semantics.I would support a change in this behaviour, if possible.
I did, unfortunately, I cannot find any ability to get around that behavior. Based on https://github.com/sindresorhus/got/blame/master/readme.md#L188 and https://github.com/sindresorhus/got/blob/master/source/normalize-arguments.ts#L348 it looks impossible. What do I miss?
Breaking backward compatibility without any option to return known behavior is not the best way, in my mind. Simple option, but I would not need to migrate the whole codebase.
I guess we should look at the closed issues and pick the most common ones. Then add these to the FAQ.