Skip to main content
1 of 2
Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17

The strtok() call here:

char* absolute_path = strtok(req_tar, "?");

will crop req_tar at the ? and make it always be equal to abs_path.

Because of this, the following condition will never be true and you'll never extract query:

if(strcmp(req_tar, abs_path) != 0)
    query = strstr(req_tar, abs_path);

But even if that condition triggered, I don't think you understand what query should be.

Given a line "GET /hello.php?name=Alice HTTP/1.1\r\n", this is what you should extract:

  • abs_path should be /hello.php
  • query should be name=Alice

And this query = strstr(req_tar, abs_path); wouldn't make query become this name=Alice.

Yuri Laguardia
  • 2.6k
  • 1
  • 10
  • 17