当服务器指定错误的内容类型时,如何在Firefox中查看PDF?


4

我正在使用带有PDF查看器插件的Mozilla Firefox。该插件已与Adobe Reader文件正确关联,以便在设置中的浏览器中查看它们。

我希望能够在Firefox中查看PDF文件而不是下载它们。当Web服务器指示文件具有这已经正常工作Content-Typeapplication/pdf。但是,某些Web服务器Content-Type为PDF 提供其他服务,例如application/octet-stream。(请参阅使用非pdf提供的PDF示例Content-Type。)

我查看了Firefox的MimeTypes.rdf文件,它似乎只支持基于非基于Internet的文件的文件扩展名的映射应用程序。(看起来它只用于Content-Type映射基于Internet的文件。)

如何让Firefox 在浏览器中查看所有 PDF文档,而不仅仅是那些带有application/pdf Content-Type?的文档?

Answers:


1

Firefox没有内容检查代码(例如linux file命令)来检测实际内容类型并依赖于Content-Type标头。

解决方法:mozplugger扩展

man 7 mozplugger

  extensions
          This is a comma separated list of extensions that should be associated with this particular mime type. The  exten‐
          sions are only used when a web server does not report what type of file it is, or when loading files directly from
          disk.

解决方法:人工互动

保存文件并在文件资源管理器中打开它;-)

解决方法:配置错误

另一种解决方法是破解mimeTypes.rdf并分配application/octet-stream相同的值application/pdf

我不建议这种解决方法。


1
mozplugger扩展的描述似乎暗示它仅在Web服务器不指示时才起作用Content-Type。(我使用Windows,所以看起来我无法测试它。)
Sam

1

您可以对具有错误响应标头的pdf文件使用Force Content-Type扩展Content-Type

例如,如果Web服务器提供,Content-Type: application/octet-stream您可以添加规则以将其转换为Content-Type: application/pdf基于pdf文件URL,如下所示:

在此输入图像描述

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.