crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

url.cc (888B)


      1 #include "httpbuffer"
      2 
      3 static string methods[] = {
      4     "HEAD", "GET", "POST", "PUT", "DELETE", "TRACE", "OPTIONS", "CONNECT"
      5 };
      6 
      7 string Httpbuffer::url() {
      8     if (firstline().empty())
      9 	return "";
     10 
     11     // The first line must be a method, followed by the URL, followed
     12     // by optional mush, as in: GET /index.html HTTP/1.1.
     13     // Match the method first.
     14     unsigned url_start = 0;
     15     for (unsigned i = 0; i < sizeof(methods) / sizeof(string) ; i++)
     16 	if (firstline().substr(0, methods[i].size()) == methods[i]) {
     17 	    url_start = methods[i].size();
     18 	    break;
     19 	}
     20     if (!url_start)
     21 	return "";
     22     while (firstline()[url_start] == ' ' && url_start < firstline().size())
     23 	url_start++;
     24 
     25     string ret;
     26     for (unsigned i = url_start;
     27 	 firstline()[i] != ' ' && i < firstline().size();
     28 	 i++)
     29 	ret += firstline()[i];
     30 
     31     debugmsg("URL of request: " + ret + "\n");
     32     return ret;
     33 }