Skip to content

Add Javadoc for MockHttpServletResponse getContentLength method #31833

Closed
@jtroussard

Description

@jtroussard

public int getContentLength() {
return (int) this.contentLength;
}

Leveraged this Class, MockHttpServletResponse, to write some tests and initially found the behavior of this getter, getContentLength, confusing. After reaching this SO post and reading the process the poster followed in their comments, the source of my confusion became clear. That being, the content length was referring to the header value for Content-Length, not the response's payload length.

https://stackoverflow.com/questions/52005034/spring-boot-test-mockhttpservletresponse-getcontentlength-return-0-despite-of

Wondered if the team/maintainers would find any value in updating the docs with a hint that would help clarify to which "length" value the API is fetching... even though it is clearly included in the method name itself. With modern IDE's auto completing and bringing up tool tips, this might help draw the focus to the "content" part of the method name. Could extend this work to the Long version of the method as well.

Would be willing to raise a PR is there is consenses.

And not to wonder off on too much of a tangent here, perhaps a more direct method to calculate/verify the payload length might be a worthwhile contribution as well.

Thoughts?

Sorry for the double issue, originally posted from a non-personal account.

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions