我有一个squid.config
文件,用于将请求路由到重定向器。我只想将text/html
mime类型传递给它。这是我必须做的配置:
url_rewrite_program /usr/bin/python3 /etc/squid3/custom_redirect.py
#only allow text/html mime types
acl html_only req_mime_type -i ^text/html$
url_rewrite_access allow html_only
#deny all other requests
url_rewrite_access deny all
当我致电网站时,我发现access.log
显示我已使用text/html
mime类型发出请求,但没有一个通过重定向。我环顾四周,但没有人似乎有同样的问题,文件使我觉得我是对的。关于为什么这不起作用的任何想法?
答案 0 :(得分:0)
TL;DR: Check MIME type from within the url_rewrite_program
I have assumed (based on what most people would probably be wanting) that what you are trying to achieve is filtering of reply MIME types, that is the MIME type of the file on the server.
You would in theory need to change req_mime_type
to rep_mime_type
however continue reading before bothering.
This is the result of the timing of various events during Squid's processing of the HTTP request.
Immediately after receiving the request from the client Squid evaluates the acls associated with url_rewrite_access
then if needed then url_rewrite_program
is run. The problem is at this point Squid does has not sent, and therefore has not received, anything to/from the server, it therefore has no way of accurately evaluating the rep_mime_type
My solution to this was to evaluate the MIME type using the script itself.
I used PHP but for Python take a look at this.