Patches for Mathopd HTTP Server
The Mathopd HTTP Server is a small, fast HTTP/1.1 server, written by Michiel Boland.
The patches below either add functionality or modify existing functionality in the system:
- Include query string in Location redirects
- User-specifed HTTP Redirect Status Code
- TLS/SSL/HTTPS support with GnuTLS or OpenSSL
Include query string in Location redirects
When using the "Location http://" syntax for redirects, Mathopd doesn't include the query string in the redirected url. For example, using the configuration:
Host example.net
Control {
Alias /
Location http://example.com
}
the following redirections occur:
- http://example.net/pages/sample.html → http://example.com/pages/sample.html
- http://example.net/pages/index.php → http://example.com/pages/index.php
- http://example.net/pages/fun.php?q=4 → http://example.com/pages/fun.php
This is not ideal; we would often like to have the query strings passed to the redirected page, as follows:
- http://example.net/pages/sample.html → http://example.com/pages/sample.html
- http://example.net/pages/index.php → http://example.com/pages/index.php
- http://example.net/pages/fun.php?q=4 → http://example.com/pages/fun.php?q=4
This patch implements that: Query String Patch for Mathopd 1.5p6, Query String Patch for Mathopd 1.6b9. This is a relatively short, simple patch, and so should apply cleanly to other versions as well.
User-specifed HTTP Redirect Status Code
Mathopd generates a "302 Moved" response when using the "Location http://" syntax for automatic redirects. This patch allows Mathopd to generate other 3xx redirect codes instead.
This patch adds a "RedirectStatus" keyword, which takes a single integer between 300 and 399. This sets the HTTP status code returned when redirecting. (In practice, only 301, 302, 303, and 307 do anything useful.)
One reason for using this patch is the Google duplicate content penalty. When multiple pages or domains have the same content, some search engines (notably Google) impose a penalty, lowering the result on the search result pages. Moreover, using a 302 redirect is considered the same as having duplicate content, while a 301 redirect is considered a permanent move, which means the content is only indexed under the redirected url.
Patch: Redirect Status (+ Query String Redirect) Patch for Mathopd 1.5p6, Redirect Status (+ Query String Redirect) Patch for Mathopd 1.6b9. This patch also includes the above query string patch.
An alternative, if you do not wish to patch your server, is to use this short CGI program: 301 Redirect CGI. Compile it to 301_cgi (bash$ gcc -o 301_cgi 301_cgi.c) and then use PutEnv to define a variable called MATHOPD_DESTINATION for the alias you wish to redirect:
Virtual {
Host example.net
Control {
Alias /
PutEnv {
MATHOPD_DESTINATION=http://example.com
}
Location /path/to/301_cgi
}
}
TLS/SSL/HTTPS support with GnuTLS
2007-10-10: This has now been superseded by the patch below, which implements both GnuTLS and OpenSSL for TLS support.
TLS/SSL/HTTPS support with GnuTLS or OpenSSL
2007-10-10: Implemented OpenSSL support. Fixed SENDFILE bug when in TLS mode. Added preliminary documentaion for TLS commands.
2007-10-08: USE_SSL_GNUTLS option is currently mutually incompatible with LINUX_SENDFILE (and probably FREEBSD_SENDFILE, although I can't test that...) If you are testing GnuTLS functionality in the current patch, please build without *_SENDFILE for the moment.
2007-09-24: Here is a preliminary patch for TLS/SSL support for Mathopd 1.5p6, based on GnuTLS. I haven't had time to clean this up and put in the relevant documentation as in the above patches, but I wanted to get it out there for people to try. The quick patch created here includes the above two patches. When I get a chance later, I'll clean it up to only include TLS, and provide the 1.6b9 version of the patch, too.
WARNING: This patch is only trivially tested, and is considered ALPHA quality for the moment! Use at your own risk, but feel free to let me know about any problems you have...
Quick HowTo:
Server {
TLS {
CACertFile ca-cert.pem
CRLFile crl.pem
CertFile cert.pem
KeyFile key.pem
DHParamsFile dhparams.pem
DHBits 1024
}
Control {
Alias /
Location /www/
}
}
CertFile is the only required option, but if KeyFile is not supplied, CertFile must contain the private key as well. DHBits defaults to 1024, DH Params are generated if not supplied (but this can take some time, so for repeated testing, a dhparams file is suggested).
Patch: TLS Patch for Mathopd 1.5p6 - beta
Contact
If there are any queries or comments regarding the above patches, they can either be directed to the Mathopd Mailing List, or to mathopd-patches@stobor.net