I'm learning about writing Apache modules for a project I'm working on. I found the official guide, which turns out to be very informative.
On the first page, "Developing modules for the Apache HTTP Server 2.4", the section "Building a handler", subsection "The request_rec
structure" provides some example code:
static int example_handler(request_rec *r)
{
/* Set the appropriate content type */
ap_set_content_type(r, "text/html");
/* Print out the IP address of the client connecting to us: */
ap_rprintf(r, "<h2>Hello, %s!</h2>", r->useragent_ip);
/* If we were reached through a GET or a POST request, be happy, else sad. */
if ( !strcmp(r->method, "POST") || !strcmp(r->method, "GET") ) {
ap_rputs("You used a GET or a POST method, that makes us happy!<br/>", r);
}
else {
ap_rputs("You did not use POST or GET, that makes us sad :(<br/>", r);
}
/* Lastly, if there was a query string, let's print that too! */
if (r->args) {
ap_rprintf(r, "Your query string was: %s", r->args);
}
return OK;
}
Something that caught my eye was the strcmp
on r->method
to see if it's POST
, GET
, or something else. That's weird. I thought the only HTTP methods were GET
and POST
? Is there something else, or just the developers (or documentors) being unneedingly cautious?