mirror of
https://github.com/swift-server/async-http-client.git
synced 2026-06-02 07:37:34 +00:00
fix: length calculation of .string HTTPBody (#11)
Currently, if an `HTTPBody` is set to .string, the length is calculated as string.count. In Swift, this is the number of extended grapheme clusters, not the UTF8 byte count. Instead, we should use the count of the UTF8View, as the bytes will be transmitted in this encoding.
This commit is contained in:
@@ -52,7 +52,7 @@ public enum HTTPBody: Equatable {
|
||||
case .data(let data):
|
||||
return data.count
|
||||
case .string(let string):
|
||||
return string.count
|
||||
return string.utf8.count
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -324,7 +324,7 @@ class HTTPTaskHandler<T: HTTPResponseDelegate>: ChannelInboundHandler, ChannelOu
|
||||
buffer.writeBytes(data)
|
||||
part = HTTPClientRequestPart.body(.byteBuffer(buffer))
|
||||
case .string(let string):
|
||||
var buffer = context.channel.allocator.buffer(capacity: string.count)
|
||||
var buffer = context.channel.allocator.buffer(capacity: string.utf8.count)
|
||||
buffer.writeString(string)
|
||||
part = HTTPClientRequestPart.body(.byteBuffer(buffer))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user