MockWebServer should allow GET with a body
See original GitHub issueokhttp3.internal.http.HttpMethod
forbids having body on GET request:
fun permitsRequestBody(method: String): Boolean = !(method == "GET" || method == "HEAD")
While I agree that this is a bad practice to use GET with a body, problem is that we have to work with 3rd party APIs which no one will ever change and they do demand GET with a body.
In this case it’s a huge show-stopper for us 😦
I propose to either remove GET from permitsRequestBody or at least make it somehow configurable.
Or, at least remove this validation from MockWebServer.
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (2 by maintainers)
Top Results From Across the Web
Unit Testing POST request body while using WebClient
It can record request body like below example. MockWebServer server = new MockWebServer(); RecordedRequest request = server.
Read more >The Recommended Way Of Testing HTTP Calls ... - Medium
What is MockWebServer? This testing library is built by the Square Team to easily test how the apps behave when making API calls....
Read more >How to Use MockWebServer to Mock and Test HTTP Calls
Hence, a mock web server allows us to make HTTP requests (test ... First, you need to create a new project if you...
Read more >Better Integration Testing with MockWebServer - Industrial Logic
Because of this, I recommend you limit the number of integration tests to as few as possible, only testing concerns that cannot be...
Read more >Test Spring WebClient with MockWebServer from OkHttp
Therefore we can construct a MockResponse matching our needs (body, HTTP header, response code) and queue it using mockWebServer.enqueue() .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As I said above:
I’m OK with maintainers decision to not support something. I do understand that if you considered GET+body as impossible then there are might be some dark corners in the code that need to be fixed in order to support this. That is OK.
If you are honest about that, then you can add little “known limitations” somewhere on this page.
But just closing tickets with “forbidden by specs” or “it’s by design” is wrong I believe, because first of all it’s not forbidden and then you don’t give a chance for somebody else to contribute.
@lazystone Thanks for the link. That project looks great, and a good argument for why OkHttp’s MockWebServer doesn’t need to try to be everything for everyone. I don’t think the OkHttp maintainers have time to compete with a well funded project like that. Fixing the issues like JDK 11 support in that project is probably the way forward.