[mod_python] Changing server signature

Graham Dumpleton grahamd at dscpl.com.au
Thu Nov 23 15:52:37 EST 2006


Lars Eriksen wrote ..
> When I return apache.NOT_FOUND,

You mean apache.HTTP_NOT_FOUND. :-)

> for example, it automatically appends 
> the following signature: "Apache/2.0.59 (Win32) mod_python/3.2.8 
> Python/2.4.4 Server at localhost Port 80"
> 
> Is there a way to change this programatically with mod_python or only in
> httpd.conf?

This server string comes from the default error pages which are generated by
Apache automatically when you return an error status. There are two ways that
you can change what is shown, but in both cases it means you will have to
construct a new error page to be used.

The first approach is to use the Apache ErrorDocument directive to specify an
alternate error page. See:

  http://httpd.apache.org/docs/2.0/mod/core.html#errordocument

By default Apache uses a set of pages which are processed using server side
include mechanism of Apache to incorporate error details and stuff such as the
server string.

Using ErrorDocument directive, it will apply to all URLs falling under the
point where you specify the ErrorDocument directive.

The second approach is to have your handler return the actual body of the error
response that you want. To do this, the handler would construct a response like
it was doing so for a normal page with the exception that it needs to set
req.status to indicate the error type. Also, if the handler is not the content
handler phase but an earlier phase, the handler must return apache.DONE as the
result rather than apache.OK. Even if the content handler phase, still
preferable to return apache.DONE if the complete response is being returned.

  from mod_python import apache

  def handler(req):
    req.status = apache.HTTP_NOT_FOUND
    req.content_type = 'text/html'
    req.write(...)
    return apache.DONE

Graham


More information about the Mod_python mailing list