Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Conversation

@comebackoneyear
Copy link
Owner

@comebackoneyear comebackoneyear commented Mar 8, 2023

The Content-Length header is missing for some JSON responses.
After some investigation, I found the following comment in the net/http documentation that states that

...if the total size of all written
data is under a few KB, and there are no Flush calls, the
Content-Length header is added automatically.

This led to the conclusion that there is no Content-Length header for longer responses because they are longer than the 2048-byte limit. However, in a lot of cases, the renderer knows the length of the response (it's a []byte or string)
This PR adds the Content-Length header in those cases.

This investigation was because we noticed gzip compression in our CDN wasn't working (Cloudfront), and we realized this was due to the missing Content-Length header.
https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-troubleshoot-compressed-files/#:~:text=Check%20your%20CloudFront%20configuration,a%20value%20greater%20than%20zero.

I have added test cases for the renderers with the added Content-Length header. There are some inconsistencies in the actual renderers and how the tests are structured, so I adapted my code to the style of the current scope.

  • With pull requests:
    • Open your pull request against master
    • Your pull request should have no more than two commits, if not you should squash them.
    • It should pass all tests in the available continuous integration systems such as GitHub Actions.
    • You should add/modify tests to cover your proposed code changes.
    • If your pull request contains a new feature, please document it on the README.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant