Hi,

I'm not sure if this is the appropriate list, or if I should post on the 
regular httpd list...

I've been trying to work with an Apache module, mod_limitipconn:

http://dominia.org/djao/limitipconn2.html

This is with Apache 2.2.8/2.2.11.

Our use case is slightly different that the original one for this module.  The 
original code is designed to limit the number of connections from any given IP 
address, whereas in my case, we want to limit the total number of connections 
to the entire Apache server instance.

To do that, I commented out one line (an 'if'), as shown below:

    /* Count up the number of connections we are handling right now from
     * this IP address */
    /* This is modified to not do strcmp(address, ws_record->client check, in 
order
       to count ALL connections to this server. */
    for (i = 0; i < server_limit; ++i) {
      for (j = 0; j < thread_limit; ++j) {
        ws_record = ap_get_scoreboard_worker(i, j);
        switch (ws_record->status) {
            case SERVER_BUSY_READ:
            case SERVER_BUSY_WRITE:
            case SERVER_BUSY_KEEPALIVE:
            case SERVER_BUSY_LOG:
            case SERVER_BUSY_DNS:
            case SERVER_CLOSING:
            case SERVER_GRACEFUL:
/*
                if (strcmp(address, ws_record->client) == 0)
*/
                    ip_count++;
                break;
            default:
                break;
        }
      }
    }

and, after I rebuilt the module, it seems to work ok.

Now, I'm trying to get the module's directive "NoIPLimit" to work.  

According to the README, plus reading the code, the way that this is suppose to 
work is that if you specify a MIME type string (substring, actually), the 
module won't "count" requests that have any of the MIME types in the directive.

I have the Apache LogLevel set to debug, and it looks like the "content_type" 
that the module is retrieving from ALL requests is "text/plain", and I have 
confirmed that the actual MIME types are not "text/plain" (I see things like 
"image/gif", "text/css", etc.), so the "NoIPLimit" directive doesn't work.

>From reading the code, I think that the "content_type" is set in this snippet:

    /* Only check the MIME-type if we have MIME-type stuff in our config.
       The extra subreq can be quite expensive. */
    if(cfg->no_limit->nelts > 0 || cfg->excl_limit->nelts > 0) {
        /* Look up the Content-type of this request. We need a subrequest
         * here since this module might be called before the URI has been
         * translated into a MIME type. */
        content_type = ap_sub_req_lookup_uri(r->uri, r, NULL)->content_type;

        /* If there's no Content-type, use the default. */
        if (!content_type) {
            content_type = ap_default_type(r);
        }

        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                "mod_limitipconn: uri: %s  Content-Type: %s",
                r->uri, content_type);

        /* Cycle through the exempt list; if our content_type is exempt,
         * return OK */
        for (i = 0; i < cfg->no_limit->nelts; i++) {
            if ((ap_strcasecmp_match(content_type, nolim[i]) == 0)
                || (strncmp(nolim[i], content_type, strlen(nolim[i])) == 0))
            {
                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                             "mod_limitipconn: OK: %s exempt", content_type);
                return DECLINED;
            }
        }

and, in particular:

        content_type = ap_sub_req_lookup_uri(r->uri, r, NULL)->content_type;

        /* If there's no Content-type, use the default. */
        if (!content_type) {
            content_type = ap_default_type(r);
        }

I'm not that familiar with Apache module development, but reading the docs, it 
*seems* like the above *should* work.

I'm assuming you all on this list *are* familiar with module development, so I 
was wondering if you might be able to tell me what, if anything, is wrong with 
that code (i.e., why is "content_type" not being set with the actual content 
type?

Thanks in advance!!

Jim

Reply via email to