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

Provide content-length in the HTTPFields' literal when creating a response #457

Closed
wants to merge 2 commits into from

Conversation

Joannis
Copy link
Contributor

@Joannis Joannis commented May 19, 2024

This allows the HTTPFields to allocate sufficient room for Content-Length, Server and Date, preventing reallocs

…ponse

This allows the HTTPFields to allocate sufficient room for `Content-Length`, `Server` and `Date`, preventing reallocs
@Joannis Joannis requested a review from adam-fowler May 19, 2024 21:04
@Joannis
Copy link
Contributor Author

Joannis commented May 19, 2024

The main issue was that contentl-length wasn't set yet, so the HTTPFields had a size of 1 due to reserveCapacity being called with 1 (from the literal). Then we were immediately adding our content-length on top of the literal, finishing it off with server and date headers.

import HTTPTypes

extension HTTPFields {
init(contentType: String, contentLength: Int) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to centralize this as an internal helper, so that we can tweak the formula from here

@Joannis
Copy link
Contributor Author

Joannis commented May 19, 2024

This is likely a great example of something that could use optimisation in HTTPFields

@adam-fowler
Copy link
Member

adam-fowler commented May 20, 2024

This was already covered in PR #454

@Joannis Joannis closed this May 20, 2024
@Joannis Joannis deleted the jo/provide-content-lengths branch May 20, 2024 18:28
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.

None yet

2 participants