Monday, February 21, 2011

Day 24 - revisiting HTTP verbs and testing

As I already told you many times, I wanted to support only GET and POST. So, that's how I started and tried to implement "meaningful" return codes (405) and error messages for other HTTP verbs. So, I started curling with -X and inadvertently tried to submit a HEAD request and have my reply send a meaningful message. That's when things started to get weird (connection closed before it should and the like). So, I went back to one of my favorite sites: W3C and more specifically to HTTP/1.1 methods definitions. That's how I realized that the HEAD is pretty much a MUST have and that it MUST NOT contain anything (content-length=0). That's where I was failing.

On top of that, this page talks about idempotence. As this is one of my leitmotivs when coding/designing interfaces, I could pass the joy of telling you that idempotence should be one of the drivers for your decision to use one of the verbs or the other. At least, that's what is in the specs. And all verbs/methods are supposed to be idempotent, except POST and CONNECT. Now, I don't think anybody cares, let alone respect that. Think of the number of websites that track the number of views for anything (pictures, videos, profiles, etc.). For all these sites, the GET is not idempotent (it increases the counter each time it processes a GET).

After 20 times typing curl -X WHATEVER -d name=daniel and other variants I finally got bored to death and decided that I needed an easier way to test my module. Using a C unit test library did not even come to my mind. However I thought of using Perl/LWP like agentzh. But that was too easy. I know Perl and I could use what agentzh did. And you know I like challenges. So, as I don't know Python (read a few examples, know there are no curly braces and that the number of spaces is important) and have been interested in learning it for years, I figured I would go for that. And, it has a unittest and a httplib libraries that should make my life easier (I like things that are not too easy but I am no masochist). And so far, a few copy/paste from the web pages of the two libraries mentioned above have already saved me quite some typing. We'll see how long this goes.

Oh, and as a side note: still no news from Valery on the review of my translation work...

No comments:

Post a Comment