Apache patch to optionally disable Partial Content


Problem

Our severs were multiple times overloaded from *.cn IP addresses with what looked like poorly setup downloader client.

Solution

I decided to stop that using a simple patch to Apache (listed below).

That patch allows us to use SetEnv nopartialcontent 1 based on request parameters (say, in a .htaccess).

And no Range requests means no multiple connections from a single client, and bye bye overloads.

Apache 1.x version

This patch for Apache adds support for disabling partial content (a.k.a.
Range request, 206) on per-request basis.

To disable partial content for given request put equivalent of:
SetEnv nopartialcontent 1
in your config (which can be done via SetEnvIf or mod_rewrite).

Author: Wejn <wejn(at)box(dot)cz>
TS: 20060723190000
Dedication: to the clients from *.cn who constantly overload our servers

diff -urN apache_1.3.36/src/main/http_protocol.c apache_1.3.36.npc/src/main/http_protocol.c
--- apache_1.3.36/src/main/http_protocol.c	2006-04-21 20:40:11.000000000 +0200
+++ apache_1.3.36.npc/src/main/http_protocol.c	2006-07-23 18:41:53.000000000 +0200
@@ -245,7 +245,7 @@
     long length, start, end, one_start = 0, one_end = 0;
     int ranges, empty;
     
-    if (!r->clength || r->assbackwards)
+    if (!r->clength || r->assbackwards || ap_table_get(r->subprocess_env, "nopartialcontent"))
         return 0;
 
     /* Check for Range request-header (HTTP/1.1) or Request-Range for

Apache 2.x version

This patch for Apache adds support for disabling partial content (a.k.a.
Range request, 206) on per-request basis.

To disable partial content for given request put equivalent of:
SetEnv nopartialcontent 1
in your config (which can be done via SetEnvIf or mod_rewrite).

(this is just adaptation of the old 1.3.X version of the patch:
https://wejn.org/stuff/apache-partial-content-new.diff.html )

Author: Wejn <wejn(at)box(dot)cz>
TS: 20070216120300
Dedication: to the clients from *.cn who constantly overload our servers

--- httpd-2.0.58/modules/http/http_protocol.c.orig	2007-02-16 11:45:40.000000000 +0100
+++ httpd-2.0.58/modules/http/http_protocol.c	2007-02-16 11:45:42.000000000 +0100
@@ -3142,7 +3142,7 @@
     const char *ct;
     int num_ranges;
 
-    if (r->assbackwards) {
+    if (r->assbackwards || apr_table_get(r->subprocess_env, "nopartialcontent")) {
         return 0;
     }