This document shows the contents of request.cpp if you are starting the tutorial in Part 4. Developing Classes in the IDE or subsequent parts.
Request::Request() {
ReqString=""; //Initialize string
ReqMethod=getenv("REQUEST_METHOD"); //Determine how input provided
if (ReqMethod=="GET") { //GET means it comes from
ReqString=getenv("QUERY_STRING"); //QUERY_STRING variable
ReqLen=ReqString.length();
}
else if (ReqMethod=="POST") { //POST means read the right number
ReqLen=atoi(getenv("CONTENT_LENGTH")); //of characters from standard input.
for (int c=1;c<=ReqLen;c++)
ReqString+=char(cin.get());
ReqString.change("&"," "); //In POST calls, an "&" separates fields
}
ReqString.change("+"," "); //In both types, a "+" replaces a space
//Special characters are escaped with % and two hex digits.
//Convert these to their actual character values
int p=ReqString.indexOf("%");
while (p>0) {
if (ReqString.subString(p+1,2).isHexDigits()) // If it's a hex pair after %
ReqString.change(
ReqString.subString(p,3), // Change % and hex pair
ReqString.subString(p+1,2).x2c(),p,1); // to char value using IString::x2c
p=ReqString.indexOf("%",p+1); // Search for next %
}
lReqString=IString::lowerCase(ReqString); // Create lowercase version for searches
//Get the file attribute's value, then set Filepath to the value of
//the WebRoot macro plus a slash plus the file name. WebRoot and slash will be
//defined shortly.
Filename=GetValue("file");
Filepath=Filename;
Filepath.change(slash,"/");
if (Filepath.subString(1,1)!=slash)
Filepath=slash+Filepath;
Filepath=WebRoot+Filepath;
Key=GetValue("key"); //Get user's key
}
IString Request::GetValue(IString Search) {
Search.lowerCase();
Search+="=*";
for (int i=1; i<=ReqString.numWords();i++)
if (lReqString.word(i).isLike(Search))
return ReqString.word(i).subString(Search.length());
return "";
}
