File: url.cc

package info (click to toggle)
crossroads 2.65-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,664 kB
  • ctags: 355
  • sloc: cpp: 4,212; perl: 1,658; xml: 269; makefile: 186; sh: 46
file content (33 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "httpbuffer"

static string methods[] = {
    "HEAD", "GET", "POST", "PUT", "DELETE", "TRACE", "OPTIONS", "CONNECT"
};

string Httpbuffer::url() {
    if (firstline().empty())
	return "";

    // The first line must be a method, followed by the URL, followed
    // by optional mush, as in: GET /index.html HTTP/1.1.
    // Match the method first.
    unsigned url_start = 0;
    for (unsigned i = 0; i < sizeof(methods) / sizeof(string) ; i++)
	if (firstline().substr(0, methods[i].size()) == methods[i]) {
	    url_start = methods[i].size();
	    break;
	}
    if (!url_start)
	return "";
    while (firstline()[url_start] == ' ' && url_start < firstline().size())
	url_start++;

    string ret;
    for (unsigned i = url_start;
	 firstline()[i] != ' ' && i < firstline().size();
	 i++)
	ret += firstline()[i];

    debugmsg("URL of request: " + ret + "\n");
    return ret;
}