Do not rely on "Content-Length" for payload size.#391
Conversation
cortinico
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Not sure I understood what this change gives us. Could explain, please?
There was a problem hiding this comment.
It comes from some tests for maxContentLength.
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.
There was a problem hiding this comment.
Now that I'm thinking copy is not needed. I could just create a new interceptor. What do you think?
There was a problem hiding this comment.
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.
Create it with a constructor and explicit arguments for better readability.
📷 Screenshots
📄 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
ChuckerInterceptorand it does not rely on theContent-Lengthheader.🚫 Breaking
No.
🛠️ How to test
Run the sample app. Responses without the
Content-Lengthheaders should display now payload size correctly. Also, some tests were written.⏱️ Next steps
Closes #209.