Support zstd HTTP compression

As of recently roblox added the ability to make native use of zstd included in the engine via EncodingService but have neglected to add it to the supported compression types in RequestAsync.

zstd is a standardized compression/encoding type for use in HTTP as defined in RFC 8878 and roblox/libcurl currently supports it as a response encoding, but currently if you want to send a body with zstd compression as a request you have to do it yourself like so.

local HttpService = game:GetService("HttpService")
local EncodingService = game:GetService("EncodingService")

local bodyData = {
	example = "Hello World!"
}

local compressedData = buffer.tostring(EncodingService:CompressBuffer(buffer.fromstring(HttpService:JSONEncode(bodyData)), Enum.CompressionAlgorithm.Zstd, 3))
print(HttpService:RequestAsync({
	Method = "POST";
	Url = "https://example.org";
	Headers = {
		["Content-Encoding"] = "zstd";
	};
	Body = compressedData;
}))

Which is slightly less ergonomic than if we could set the Compress field in RequestAsync to Enum.HttpCompression.Zstd

This isn’t exactly urgent as you can achieve this by yourself with some boilerplate, but it sure would be nicer to not need this boilerplate code.

6 Likes