question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MockWebServer should allow GET with a body

See original GitHub issue

okhttp3.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:closed
  • Created 4 years ago
  • Comments:15 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
lazystonecommented, Mar 6, 2020

As I said above:

That’s Ok, but then please stop saying that it’s forbidden by specs

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.

2reactions
yschimkecommented, Mar 21, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found