Skip to content

Instantly share code, notes, and snippets.

@mferrier
Created August 25, 2011 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mferrier/1170703 to your computer and use it in GitHub Desktop.
Save mferrier/1170703 to your computer and use it in GitHub Desktop.
/* Copyright (c) 2011 Dirk-Willem van Gulik, All Rights Reserved.
* <dirkx(at)webweaving(dot)org>
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Binaries available at
* http://people.apache.org/~dirkx/BINARIES.txt
*
* $Id: mod_rangecnt.c 1004 2011-08-24 14:42:21Z dirkx $
*/
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_protocol.h" // NetWare to get ap_hook_post_read_request() proto;
#ifndef MAXRANGEHEADERS
#define MAXRANGEHEADERS (5)
#endif
module AP_MODULE_DECLARE_DATA rangecnt_module;
static apr_status_t ap_rangecnt_early(request_rec *r)
{
/* Should we also do Request-Range and their ilk ?? */
const char *p = apr_table_get(r->headers_in, "Range");
int c = 0;
if (p) {
for (; *p; p++) {
if (*p == ',')
c++;
};
if (c > MAXRANGEHEADERS) {
ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
"Rejected on a Range: header with more than "
"%d ranges (has %d)", MAXRANGEHEADERS, c);
return HTTP_RANGE_NOT_SATISFIABLE;
};
};
return DECLINED;
}
static void register_hooks(apr_pool_t * p)
{
ap_hook_post_read_request(ap_rangecnt_early, NULL, NULL, APR_HOOK_FIRST);
}
#ifdef AP_DECLARE_MODULE
AP_DECLARE_MODULE(rangecnt) =
#else
module AP_MODULE_DECLARE_DATA rangecnt_module =
#endif
{
STANDARD20_MODULE_STUFF,
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server configs */
NULL, /* command apr_table_t */
register_hooks /* register hooks */
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment