Skip to content

Commit 7d11ff0

Browse files
TiberiumFusionpingu7867
authored andcommitted
Handle multiple mime types in server responses
This enables pac to properly download and display remote content when the server providing it uses mime type strings such as "image/png,application/binary". This in turn fixes the loading of pngs and jpgs from some servers (notably Google drive).
1 parent e9b78b4 commit 7d11ff0

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

lua/pac3/libraries/resource.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ local function download(from, to, callback, on_fail, on_header, check_etag, etag
139139

140140
local allowed = {
141141
[".txt"] = true,
142+
[".jpeg"] = true,
142143
[".jpg"] = true,
143144
[".png"] = true,
144145
[".vtf"] = true,
@@ -150,7 +151,20 @@ local function download(from, to, callback, on_fail, on_header, check_etag, etag
150151
function(body, len, header)
151152
do
152153
if need_extension then
153-
local ext = header["Content-Type"] and (header["Content-Type"]:match(".-/(.-);") or header["Content-Type"]:match(".-/(.+)")) or "dat"
154+
local ext = "dat"
155+
if header["Content-Type"] then
156+
for _, mime in ipairs( string.Split(header["Content-Type"], ',') ) do -- some common services, including google, serve multi-item mime strings like "image/png,application/binary"
157+
subtype = mime:match(".-/(.-);") or mime:match(".-/(.+)")
158+
if subtype then
159+
subtype = subtype:lower()
160+
if allowed['.' .. subtype] then
161+
ext = subtype
162+
break -- take the first subtype (if any) found in our whitelist
163+
end
164+
end
165+
end
166+
end
167+
154168
if ext == "jpeg" then ext = "jpg" end
155169

156170
if body:StartWith("VTF") then

0 commit comments

Comments
 (0)