Got: Add an option to allow GET with body

Created on 17 Feb 2020  Â·  7Comments  Â·  Source: sindresorhus/got

Currently Got throws TypeError: The GET method cannot be used with a body when you try to upload some data using the GET method. The RFC 7231 doesn't specify any particular behavior regarding this situation. Undefined behavior is considered to be an anti-pattern.

Although this has been discussed in some issues, there are many people who are still interested in this. Sometimes the HTTP servers don't follow the RFC. We have already added an option to ignore invalid cookies. The proposed solution is to disable the error via another option, for example ~ignoreStrictPayload~ allowGetBody.

enhancement ✭ help wanted ✭

Most helpful comment

In addition, to anyone that decides to work on this. The docs should strongly advice against using this option and explain that it's an anti-pattern and that HTTP2 doesn't allow a GET with body. That it's only meant to interact with non-compliant servers when you have no other choice.

All 7 comments

Wouldn't it be clearer with an option called allowGetBody?

Sure.

In addition, to anyone that decides to work on this. The docs should strongly advice against using this option and explain that it's an anti-pattern and that HTTP2 doesn't allow a GET with body. That it's only meant to interact with non-compliant servers when you have no other choice.

Hey @sindresorhus , i just migrated from request to got and might have a edge case where I may have to support a body on a GET request. I was looking through the code and it would like to contribute a PR to fix this issue with the option allowGetBody as discussed. Could i take this up if no-one is working on this right now?
Also looking through the code, i noticed we don't support body on both GET and HEAD requests. Since the RFC 7321 isn't clear on whether we should support a body on a HEAD request, should we think about supporting this as well? (Although i can't imagine a use case where a HEAD request could have a body). Thanks.

Could i take this up if no-one is working on this right now?

Sure. Feel free.

Since the RFC 7321 isn't clear on whether we should support a body on a HEAD request, should we think about supporting this as well?

Personally I think that we shouldn't do that for HEAD, as it's used only for scraping headers. If there would be any use case, then it should be another issue.

Should be fixed with PR #1081

I think this issue can be closed @sindresorhus @szmarczak

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joolfe picture joolfe  Â·  3Comments

framerate picture framerate  Â·  4Comments

alvis picture alvis  Â·  3Comments

dAnjou picture dAnjou  Â·  3Comments

f-mer picture f-mer  Â·  4Comments