crossroads

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

firstline.cc (1058B)


      1 #include "httpbuffer"
      2 
      3 string &Httpbuffer::firstline() {
      4     PROFILE("Httpbuffer::firstline");
      5 
      6     // Already determined? Re-return.
      7     if (first_line.size()) {
      8 	debugmsg("Previously determined first buffer line: " << first_line <<
      9 		 '\n');
     10 	return first_line;
     11     }
     12 
     13     // Extract the first line
     14     for (unsigned i = 0; i < bufsz(); i++) {
     15 	char ch = charat(i);
     16 	if (ch == '\n' || ch == '\r')
     17 	    break;
     18 	first_line += ch;
     19     }
     20 
     21     // Buffer must start with a known HTTP label, else we're in a TCP 
     22     // transmission
     23     static string http_label[] = {
     24 	// Request labels
     25 	"OPTIONS ", "GET ", "HEAD ", "POST ", "PUT ", "DELETE ", "TRACE ",
     26 	"CONNECT ",
     27 	// Response labels
     28 	"HTTP/",
     29 	// Stopper
     30 	""
     31     };
     32 
     33     bool is_label = false;
     34     for (unsigned int i = 0; http_label[i] != ""; i++)
     35 	if (!strncmp(first_line.c_str(), http_label[i].c_str(),
     36 		     http_label[i].length())) {
     37 	    is_label = true;
     38 	    break;
     39 	}
     40     if (!is_label)
     41 	first_line = "";
     42 
     43     debugmsg("First line determined as: [" << first_line << "]\n");
     44     return first_line;
     45 }