Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Suggestion: Use default request body if request body is null when POST, PUT, PATCH... #78

Open
10000-ki opened this issue Aug 3, 2021 · 0 comments

Comments

@10000-ki
Copy link

10000-ki commented Aug 3, 2021

Hello there,

First of all
I'm using this library well in my project. Thank you!!.

I found an issue that it doesn't allow empty request body except GET

### Send request with no request's body
POST https://httpbin.org/post

> {%
  client.test("Response is ok", function() {
    client.assert(response.status === 200, "Response status is not ok");
  });
%}

Perhaps this is the effect of the OkHttpRequest library.

However it doesn't matter in IntelliJ, and it works well.

How about using default request body if request doesn't have a request body when http method is post, put, patch..

// example
private fun getRequestBody(request: Request): RequestBody? {
        val body = request.body?.toRequestBody() ?: request.createMultipartRequestBody()

        if (HttpMethod.requiresRequestBody(request.method.name) && body == null) {
            return "{}".toRequestBody()
        }

        return body
}

so if you don't mind i can raise a PR soon

with pleasure

@10000-ki 10000-ki changed the title Unable to run with out request body when http method is post Unable to run without request body when http method is post Aug 3, 2021
@10000-ki 10000-ki changed the title Unable to run without request body when http method is post Suggestion: use default request body Aug 3, 2021
@10000-ki 10000-ki changed the title Suggestion: use default request body Suggestion: Use default request body When POST, PUT, PATCH... Aug 3, 2021
@10000-ki 10000-ki changed the title Suggestion: Use default request body When POST, PUT, PATCH... Suggestion: Use default request body if request body is null when POST, PUT, PATCH... Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant