openvsx icon indicating copy to clipboard operation
openvsx copied to clipboard

Web extension resources return incorrect MIME type

Open amvanbaren opened this issue 2 years ago • 16 comments

Contributes to #468 Use Apache Tika to detect mimetype

amvanbaren avatar Jun 09 '22 17:06 amvanbaren

@amvanbaren I just found that mime types are listed in the [Content_Types].xml file inside the vsix :facepalm: So we just need to parse it and use the rules in there

<?xml version="1.0" encoding="utf-8"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
	<Default Extension=".json" ContentType="application/json"/>
	<Default Extension=".vsixmanifest" ContentType="text/xml"/>
	<Default Extension=".png" ContentType="image/png"/>
	<Default Extension=".md" ContentType="text/markdown"/>
	<Default Extension=".js" ContentType="application/javascript"/>
	<Default Extension=".map" ContentType="application/json"/>
	<Default Extension=".txt" ContentType="text/plain"/>
	<Default Extension=".woff2" ContentType="font/woff2"/>
	<Default Extension=".html" ContentType="text/html"/>
	<Default Extension=".css" ContentType="text/css"/>
</Types>

jeanp413 avatar Jun 09 '22 17:06 jeanp413

Some more info https://docs.microsoft.com/en-us/visualstudio/extensibility/the-structure-of-the-content-types-dot-xml-file?view=vs-2022#attribute-name-attribute-1 vsix files should be application/zip and all other file types application/octet-stream

jeanp413 avatar Jun 09 '22 18:06 jeanp413

I just found that mime types are listed in the [Content_Types].xml file inside the vsix 🤦 So we just need to parse it and use the rules in there.

Ok, I'll use that file to assign the right content type to a file resource. If the resource isn't listed then application/octet-stream is used.

vsix files should be application/zip and all other file types application/octet-stream

When I download a vsix file, then the content-type is application/vsix content-type-application-vsix

amvanbaren avatar Jun 10 '22 07:06 amvanbaren

When I download a vsix file, then the content-type is application/vsix

Then their docs are outdated :sweat_smile:

jeanp413 avatar Jun 10 '22 12:06 jeanp413

Need to test what happens when some files don't have file extension, e.g sometimes README files don't have the .md extension, maybe we should add some default rules by filename

jeanp413 avatar Jun 10 '22 17:06 jeanp413

From my testing, @jeanp413, if there is no extension present, it will not be in the [Content_Types].xml file. Do you think there could be cases in which serving everything with no extension with a text/plain would not work?

This is just concerning web extensions, correct? So there will be no binaries served, which are the only thing in my mind that don't usually have extensions.

cc @amvanbaren

filiptronicek avatar Jul 01 '22 09:07 filiptronicek

Thanks for testing this, @filiptronicek, from the MS docs anything else should be application/octet-stream. Looking at vsce source code they allow license without extension but then they add the file extension if it's missing when packaged so we won't have any issue :tada:

jeanp413 avatar Jul 01 '22 15:07 jeanp413

@amvanbaren I saw openvsx got finally deployed :tada:, can we merge this so it's shipped in next deployment :slightly_smiling_face: BTW, can you share until which commit got deployed?

jeanp413 avatar Sep 27 '22 03:09 jeanp413

can we merge this so it's shipped in next deployment 🙂

Yes, I'll rebase and complete this PR.

BTW, can you share until which commit got deployed?

Up until PR #517 is deployed. Production is 25 commits behind master.

amvanbaren avatar Sep 27 '22 06:09 amvanbaren

@amvanbaren let's merge :pray:

jeanp413 avatar Nov 14 '22 19:11 jeanp413

@amvanbaren let's merge 🙏

@jeanp413 Has this been reviewed and tested?

amvanbaren avatar Nov 14 '22 19:11 amvanbaren

I thought it was already approved :sweat_smile: , will take a look

jeanp413 avatar Nov 14 '22 20:11 jeanp413

This PR is missing a migration: https://github.com/eclipse/openvsx/issues/468#issuecomment-1323388969

amvanbaren avatar Nov 22 '22 09:11 amvanbaren

@filiptronicek if you have some free time could you test this :pray: ?

jeanp413 avatar Nov 22 '22 21:11 jeanp413

Same priority as #468

kineticsquid avatar Jan 17 '23 18:01 kineticsquid

Ok, I've fixed the PR. @filiptronicek Do you have time to test it?

amvanbaren avatar Jul 04 '23 15:07 amvanbaren