httpclient icon indicating copy to clipboard operation
httpclient copied to clipboard

HTTPClient.create_request should not set content type for empty bodies

Open rob-spoor opened this issue 5 years ago • 0 comments

For REST APIs, it's quite common to have POST (and possibly PUT) methods that do not require a body. In method request_async2, any nil body gets transformed into an empty string. When create_request is called through do_request_async, it sets the content type to application/x-www-form-urlencoded if the body is "true" and no content type is provided. However, that should not be necessary if the body is empty.

As a workaround we now had to explicitly specify a content type (text/plain), but it would be better to simply not set a default content type if the body is empty.

Note that this is an issue that only occurs when using the async methods; the non-async methods do not transform nil bodies into empty strings.

rob-spoor avatar Aug 11 '20 07:08 rob-spoor