Skip to content

Do not rely on "Content-Length" for payload size.#391

Merged
vbuberen merged 6 commits into
ChuckerTeam:developfrom
MiSikora:payload-size
Jul 25, 2020
Merged

Do not rely on "Content-Length" for payload size.#391
vbuberen merged 6 commits into
ChuckerTeam:developfrom
MiSikora:payload-size

Conversation

@MiSikora

@MiSikora MiSikora commented Jul 19, 2020

Copy link
Copy Markdown
Contributor

📷 Screenshots

Before After
Screenshot_20200719-064434 Screenshot_20200719-064034

📄 Context

There is an open issue - #209. Also, recently the community asked for it.

📝 Changes

Two main changes. I redesigned a little bit DB entities to reflect that they have payload size and not content length. This required a destructive migration. Since this is changed, the field is set after the response read is done by ChuckerInterceptor and it does not rely on the Content-Length header.

🚫 Breaking

No.

🛠️ How to test

Run the sample app. Responses without the Content-Length headers should display now payload size correctly. Also, some tests were written.

⏱️ Next steps

Closes #209.

@cortinico cortinico left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just a couple of small comments 👌

* that the client downloaded even if the [file] is corrupted.
*/
fun onClosed(file: File)
fun onClosed(file: File, totalBytesRead: Long)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's invert the parameter order either here or in the onFailure:

fun onClosed(file: File, totalBytesRead: Long)
fun onFailure(file: File, exception: IOException)

File should always be either the first or the last param.

@vbuberen vbuberen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks there. Just a minor comment update and we are good to merge.

* Called when the upstream was closed. All read bytes are copied to the [file].
* This does not mean that the content of a [file] is valid. Only that the user
* is done with the reading process.
* This does not mean that the content of the [file] is valid. Only that the user

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor observation - I guess user on this line and client on 95 mean the same thing. Suggest to pick one word for naming. client seems more suitable for this case.

fileFactory: FileFactory,
maxContentLength: Long = 250000L,
headersToRedact: Set<String> = emptySet()
internal data class ChuckerInterceptorDelegate(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understood what this change gives us. Could explain, please?

@MiSikora MiSikora Jul 25, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes from some tests for maxContentLength.

fun payloadSize_isNotLimitedByInterceptorMaxContentLength(factory: ClientFactory) {
val body = Buffer().apply {
repeat(10_000) { writeUtf8("!") }
}
server.enqueue(MockResponse().setBody(body))
val request = Request.Builder().url(serverUrl).build()
val chuckerInterceptor = chuckerInterceptor.copy(maxContentLength = 1_000)
val client = factory.create(chuckerInterceptor)
client.newCall(request).execute().readByteStringBody()
val transaction = chuckerInterceptor.expectTransaction()
assertThat(transaction.responsePayloadSize).isEqualTo(body.size())
}

Since the interceptor is created in setUp there is no way of changing its input parameters. I wanted to have more granular control over that and an explicit test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I'm thinking copy is not needed. I could just create a new interceptor. What do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be a question of preference. I think creation of a new interceptor would be sort of more understandable for a new reader of the code.

Michał Sikora added 3 commits July 25, 2020 17:00
Create it with a constructor and explicit arguments for better readability.
@vbuberen vbuberen merged commit ba2c21b into ChuckerTeam:develop Jul 25, 2020
@MiSikora MiSikora deleted the payload-size branch August 22, 2020 10:31
@vbuberen vbuberen added this to the 3.3.0 milestone Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Payload size isn't correct for some transactions

3 participants