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.

AndroidClientEngine set a Content-Lenght: 2 on a GET request with an EmptyContent as body

See original GitHub issue

Ktor Version and Engine Used (client or server and name) 1.3.2

Describe the bug

  1. On a GET request, the body is an EmptyContent
  2. The JsonFeature with a KotlinxSerializer serialize this EmptyContent as {} Code Here
  3. The AndroidClientEngine calculate Content-Length based on this {} and set it to 2 Code Here
  4. Then the GET request is executed without body but with a Content-Lenght: 2 header

Expected behavior GET request executed without body and with a Content-Lenght: 0 header

Maybe, this PR could resolve this issue ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kwikycommented, May 27, 2020

I think i found a solution I have to set the content-type only when necessary :

        if (method == HttpMethod.Post || method == HttpMethod.Put || method == HttpMethod.Patch) {
            contentType(ContentType.Application.Json)
        }
0reactions
e5lcommented, Oct 26, 2020

Fixed in 1.4.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

EmptyContent - ktor
Concrete OutgoingContent without a payload. Functions Properties Extensions. Functions. getProperty.
Read more >
Web API - Handling HEAD requests and specify custom ...
Return a Body with at least one byte content, set the Content-Length-Header of the response to the desired length. Using a Body with...
Read more >
Retrofit2 doesn't handle empty content responses - Ken Yee
The workaround is to add a null delegating converter in front of the JSON converter for Retrofit2. class NullOnEmptyConverterFactory implements Converter.
Read more >
https://raw.githubusercontent.com/ktorio/ktor/mast...
receiveText() tries to parse body as JSON when the ContentNegotiation plugin is ... Document how to enable/disable HTTP/2 for different client engines ...
Read more >
REST Request Test Step | ReadyAPI Documentation
The REST Request test step sends a REST request of the specified type (GET, POST, PUT and so on), gets a response and...
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