mirror of
https://github.com/lune-org/lune.git
synced 2024-12-13 21:40:40 +00:00
Add test for automatic decompression in net builtin
This commit is contained in:
parent
52c6f21aba
commit
3bc0e129b3
2 changed files with 57 additions and 0 deletions
|
@ -49,6 +49,7 @@ create_tests! {
|
|||
fs_move: "fs/move",
|
||||
|
||||
net_request_codes: "net/request/codes",
|
||||
net_request_compression: "net/request/compression",
|
||||
net_request_methods: "net/request/methods",
|
||||
net_request_query: "net/request/query",
|
||||
net_request_redirect: "net/request/redirect",
|
||||
|
|
56
tests/net/request/compression.luau
Normal file
56
tests/net/request/compression.luau
Normal file
|
@ -0,0 +1,56 @@
|
|||
local net = require("@lune/net")
|
||||
|
||||
-- Should decompress automatically by default
|
||||
|
||||
local response = net.request({
|
||||
url = "https://httpbingo.org/gzip",
|
||||
headers = {
|
||||
["Accept-Encoding"] = "gzip",
|
||||
},
|
||||
})
|
||||
|
||||
assert(
|
||||
response.ok,
|
||||
"Request failed with status "
|
||||
.. tostring(response.statusCode)
|
||||
.. " "
|
||||
.. tostring(response.statusMessage)
|
||||
)
|
||||
|
||||
local success, json = pcall(net.jsonDecode, response.body)
|
||||
assert(success, "Failed to decode json response\n" .. tostring(json))
|
||||
|
||||
-- Content encoding header should no longer exist when automatically decompressed
|
||||
|
||||
assert(
|
||||
response.headers["content-encoding"] == nil,
|
||||
"Content encoding header still exists after automatic decompression"
|
||||
)
|
||||
|
||||
-- Should do nothing when explicitly disabled
|
||||
|
||||
local response2 = net.request({
|
||||
url = "https://httpbingo.org/gzip",
|
||||
headers = {
|
||||
["Accept-Encoding"] = "gzip",
|
||||
},
|
||||
options = { decompress = false },
|
||||
})
|
||||
|
||||
assert(
|
||||
response2.ok,
|
||||
"Request failed with status "
|
||||
.. tostring(response2.statusCode)
|
||||
.. " "
|
||||
.. tostring(response2.statusMessage)
|
||||
)
|
||||
|
||||
local success2 = pcall(net.jsonDecode, response2.body)
|
||||
assert(not success2, "Decompression disabled still returned json response")
|
||||
|
||||
-- Content encoding header should still exist when not automatically decompressed
|
||||
|
||||
assert(
|
||||
response2.headers["content-encoding"] ~= nil,
|
||||
"Content encoding header is missing when automatic decompression is disabled"
|
||||
)
|
Loading…
Reference in a new issue