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

Correctly calculate Content-Length as a byte size #4

Merged
merged 1 commit into from Dec 4, 2015

Conversation

davidcelis
Copy link
Contributor

The HTTP server currently is calculating Content-Length as a naive
character count, but the header is supposed to be the byte size of the
response contents. In the case of "Hello World", the two are equivalent,
but, if the response contained special characters, the Content-Length
would be incorrect:

print("moose".characters.count) // 5
print("møøse".characters.count) // 5
print("møøse".utf8.count) // 7

For semantic reasons, and for people who are copying the source to serve
their own custom responses, we should provide the correct byte length.

Signed-off-by: David Celis me@davidcel.is

The HTTP server currently is calculating Content-Length as a naive
character count, but the header is supposed to be the byte size of the
response contents. In the case of "Hello World", the two are equivalent,
but, if the response contained special characters, the Content-Length
would be incorrect:

```swift
print("moose".characters.count) // 5
print("møøse".characters.count) // 5
print("møøse".utf8.count) // 7
```

For semantic reasons, and for people who are copying the source to serve
their own custom responses, we should provide the correct byte length.

Signed-off-by: David Celis <me@davidcel.is>
@huytd
Copy link
Owner

huytd commented Dec 4, 2015

👍 thank you very much!

huytd added a commit that referenced this pull request Dec 4, 2015
Correctly calculate Content-Length as a byte size
@huytd huytd merged commit 3827246 into huytd:master Dec 4, 2015
@davidcelis davidcelis deleted the content-length branch December 4, 2015 20:38
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