Skip to content

Commit 3827246

Browse files
committed
Merge pull request #4 from davidcelis/content-length
Correctly calculate Content-Length as a byte size
2 parents 5c32dbc + adb64b4 commit 3827246

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/http.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@ public class HTTP {
4949
let clientSocket = accept(serverSocket, nil, nil)
5050

5151
let msg = "Hello World"
52+
let contentLength = msg.utf8.count
5253

5354
echo(clientSocket, "HTTP/1.1 200 OK\n")
5455
echo(clientSocket, "Server: Swift Web Server\n")
55-
echo(clientSocket, "Content-length: \(msg.characters.count)\n")
56+
echo(clientSocket, "Content-length: \(contentLength)\n")
5657
echo(clientSocket, "Content-type: text-plain\n")
5758
echo(clientSocket, "\r\n")
5859

5960
echo(clientSocket, msg)
6061

61-
print("Response sent: '\(msg)' - Length: \(msg.characters.count)")
62+
print("Response sent: '\(msg)' - Length: \(contentLength)")
6263

6364
close(clientSocket)
6465
}

0 commit comments

Comments
 (0)