I'm getting the following errors when testing via curl:

Terminal 1

curl -i http://localhost:8080/hello.php?q=Lucky

HTTP/1.1 301 Moved Permanently

Location: /

Terminal 2

GET /hello.php?q=Lucky HTTP/1.1

Parsed: GET, /hello.php?q=Lucky, HTTP/1.1

abs_path /hello.php

query q=Lucky

Can anyone deduce from those where my bug might be?


I faced this error quite a bit. It turned out that I had a problem in my parse function. It took a lot of patient debugging, but the error came down to not having my abs_path and query variables null-terminated properly.

There's only one function that can generate a 301 error. I believe it's called around lines 218-226. I placed printf statements around that section to confirm that that's where my problem was.

There could be other bugs that get you to this point, but this is how I addressed the endless 301 errors in my program.

  • Peter, thx again. So what you are saying is, that although my printf() statements look ok here, there might be still the issue of not nul-terminating properly in my parse(). I guess my implementation with strtok_r() could be the source!?. What functions did you use to implement parse() ? – gado007 Feb 28 '16 at 16:18
  • I used a combination of the following: strcpy, strncpy, strcmp, strncmp, strchr, and strrchr. It may not be the most elegant, but it works. Also, I used malloc to allocate memory for both abs_path and query without noticing that right before parse is called, the code already declares their size. Once I addressed that issue and added '\0' to the end of the relevant variables, parse worked. – Peter Feb 28 '16 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .