libmagic.文字/纯文字,而不是文字/javascript文字/css [英] libmagic. text/plain instead of text/javascript text/css

查看:45
本文介绍了libmagic.文字/纯文字,而不是文字/javascript文字/css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用libmagic在项目的Web界面中获取文件的mime类型.我在css和js文件上得到了text/plain mime类型.

例如铬显示以下警告:

 资源解释为样式表,但以MIME类型text/plain传输:"http://localhost:8000/jquery-ui.css".资源被解释为脚本,但以MIME类型text/plain进行传输:"http://localhost:8000/jquery.timers.js". 

Http对话框

  alex @ alex-laptop〜$ nc本地主机8000GET/ui.css HTTP/1.1HTTP/1.1 200 OK连接方式:关闭内容长度:699内容类型:文本/纯文本;字符集= us-ascii日期:2012年9月19日,星期三,格林尼治标准时间... 

我该如何解决?

解决方案

您将需要执行与Apache相同的操作:查阅MIME类型的扩展数据库,如果失败,请查阅libmagic.

文本和XML文件通常过于通用,以至于lib​​magic无法弄清.libmagic仅用于通过检查几个字节来确定文件类型,因此CSS和JavaScript不能完全不同来确定其确切类型.对于XML,libmagic必须具有相当复杂的规则才能确定文件是XHTML,SVG,XHTML + SVG还是生成XHTML和/或SVG的XSLT.那超出了它的范围.

I use libmagic to get the mime type of a file in a web interface of my project. I get text/plain mime type on css and js files.

For example chromium shows below warnings:

Resource interpreted as Stylesheet but transferred with MIME type text/plain: "http://localhost:8000/jquery-ui.css".
Resource interpreted as Script but transferred with MIME type text/plain: "http://localhost:8000/jquery.timers.js".

Http dialog

alex@alex-laptop ~ $ nc localhost 8000
GET /ui.css HTTP/1.1


HTTP/1.1 200 OK
Connection: close
Content-Length: 699
Content-Type: text/plain; charset=us-ascii
Date: Wed, 19 Sep 2012 11:41:48 GMT

...

How can I fix this?

解决方案

You'll need to do the same thing as Apache: consult a database of extensions for the MIME type, and, if you fail, consult libmagic.

Text and XML files are often too generic for libmagic to figure out. libmagic is only meant to determine a file type by examining a few bytes, so CSS and JavaScript are insufficiently distinct to determine their exact types. In the case of XML, libmagic would have to have fairly sophisticated rules to determine if a file was XHTML, SVG, XHTML+SVG, or an XSLT that produces XHTML and/or SVG. That's beyond its scope.

这篇关于libmagic.文字/纯文字,而不是文字/javascript文字/css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆