Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MockResponse wrong content-length #4682

Closed
lazar-otasevic-cif opened this issue Feb 13, 2023 · 3 comments
Closed

MockResponse wrong content-length #4682

lazar-otasevic-cif opened this issue Feb 13, 2023 · 3 comments

Comments

@lazar-otasevic-cif
Copy link

lazar-otasevic-cif commented Feb 13, 2023

Version

3.4.0

Summary

this function takes wrong body length - it takes string character count body.length but that does not match utf8 byte-count that is body.encodeUtf8().length in general case, so it causes bugs with some characters inside the body:

  constructor(
      body: String,
      statusCode: Int = 200,
      headers: Map<String, String> = emptyMap(),
      delayMillis: Long = 0,
  ) : this(
      statusCode = statusCode,
      body = flowOf(body.encodeUtf8()),
      headers = headers + mapOf("Content-Length" to body.length.toString()),
      delayMillis = delayMillis,
  )

Steps to reproduce the behavior

No response

Logs

(Your logs here)
@martinbonnin
Copy link
Contributor

Hi 👋
Can you check with the latest version (3.7.4) ? I'm almost sure this has been fixed there.

@martinbonnin
Copy link
Contributor

My bad, it's still there, I'll fix it. In the meantime, you can use with the Builder version:

val response = MockResponse.Builder().body("hello world").build()

Is is certainly a safer bet anyways as the constructor is deprecated and will be removed at some point.

@BoD
Copy link
Contributor

BoD commented Mar 15, 2023

This has been released as part of v3.7.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants