阅读正文之前拒绝一个HTTP请求 [英] Rejecting a HTTP request before reading the body

查看:181
本文介绍了阅读正文之前拒绝一个HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个网站,用户需要上传一些非常大的文件上。该网站是用PHP编写的。

I'm working on a website where users will need to upload some very large files. The site is written in PHP.

有某些情况下,我会想要拒绝基于该头文件。理想情况下,我想作为报头而没有阅读机构收到后立即拒绝请求。没有理由读取200M文件,如果标题是足以告诉该文件应予驳回。此外,当我接受请求,我想定期保存为收到请求主体读取的字节数。

There are some instances where I'll want to reject a file based off the headers. Ideally, I'd like to reject the request as soon as the headers are received without ever reading the body. There's no reason to read a 200M file if the header is enough to tell that the file should be rejected. Additionally, when I do accept a request, I'd like to periodically save the number of bytes read as the request body is received.

我知道这是不可能的PHP,因为整个HTTP请求读取PHP沾到它的手了。我有什么办法?我从来没有用Perl的工作,但我读了mod_perl的可访问Apache的API。有没有可能做到这一点使用的mod_perl? Apache模块?

I know this is impossible with PHP because the entire HTTP request is read before PHP gets its hands on it. What are my alternatives? I've never worked with Perl, but I was reading that mod_perl gives access to the Apache API. Would it be possible to do this using mod_perl? An Apache module?

推荐答案

有是可以与简单的正则表达式中使用的ModSecurity。即变为在Apache2的和被接收整个文件之前被执行。你可以通过阅读文档有点开始:

There is modsecurity that can be used with "simple" regex. That goes in Apache2 and is executed before the whole file is received. You can start by reading the docs a bit:

<一个href=\"http://www.modsecurity.org/documentation/modsecurity-apache/2.5.5/modsecurity2-apache-reference.html\" rel=\"nofollow\">http://www.modsecurity.org/documentation/modsecurity-apache/2.5.5/modsecurity2-apache-reference.html

您可以保留默认的规则,因为他们原本也将禁止许多无用的访问,但它需要时间来消除实际prevent自己的网站上有许多的工作权利的那些规则,所以删除所有这些默认的规则可以是一个好主意。

You may keep the default rules too since they will also forbid many useless accesses, although it takes time to remove those rules that actually prevent your own website to work right with many, so removing all of those default rules could be a good idea.

这篇关于阅读正文之前拒绝一个HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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