Question

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?

Was it helpful?

Solution

The set of common methods is defined is RFC2616.

  • OPTIONS
  • GET
  • HEAD
  • POST
  • PUT
  • DELETE
  • TRACE
  • CONNECT

But there are many additional methods used by other protocols. For example the WEBDAV protocol defines all of these:

  • PROPFIND
  • PROPPATCH
  • MKCOL
  • COPY
  • MOVE
  • LOCK
  • UNLOCK

There is a draft RFC with a list of all the known extension methods. But in the future it is expected that new methods will be registered with the IANA in the HTTP method registry as described here.

OTHER TIPS

Yes, there are.

OPTIONS Request options of a Web page
GET     Request to read a Web page
HEAD    Request to read a Web page
PUT     Request to write a Web page
POST    Append to a named resource (e.g. a Web page)
DELETE  Remove the Web page
LINK    Connects two existing resources
UNLINK  Breaks an existing connection between two resources

For a full reference check the HTTP Specification (RFC2616, Chapter 5.1.1)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top