23 #include "HttpRequest.h"
26 void HttpRequest::unbase64(
string str)
29 authinfo[
"Method"] = (str.substr(0,str.find(
" ")));
30 str = str.substr(str.find(
" ")+1);
50 unsigned char *input = (
unsigned char *)str.c_str();
51 int length = str.length();
52 string temp = CryptoHandler::base64decode(input,length);
55 authinfo[
"Username"] = (temp.substr(0,temp.find(
":")));
56 temp = temp.substr(temp.find(
":")+1);
57 authinfo[
"Password"] = (temp);
60 void HttpRequest::getOauthParams(
string str)
62 authinfo[
"Method"] = str.substr(0,str.find(
" "));
63 str = str.substr(str.find(
" ")+1);
67 StringUtil::split(tempv, str, (
","));
68 for(
unsigned int i=0;i<tempv.size();i++)
71 StringUtil::split(tempvv, tempv.at(i), (
"="));
72 StringUtil::replaceFirst(tempvv.at(0),
"\r",
"");
73 StringUtil::replaceFirst(tempvv.at(0),
"\n",
"");
74 string temr = tempvv.at(1);
75 temr = temr.substr(temr.find(
"\"")+1);
76 temr = temr.substr(0,temr.find(
"\""));
77 authinfo[tempvv.at(0)] = temr;
78 authorderinf[authorderinf.size()+1] = CryptoHandler::urlDecode(tempvv.at(0));
83 HttpRequest::HttpRequest()
85 logger = Logger::getLogger(
"HttpRequest");
88 HttpRequest::HttpRequest(strVec vec,
string path)
93 bool contStarts =
false;
95 for(
unsigned int i=0;i<vec.size();i++)
97 strVec temp,vemp,memp;
98 if((vec.at(i)==
"\r" || vec.at(i)==
""|| vec.at(i)==
"\r\n") && !contStarts)
105 StringUtil::split(temp, vec.at(i), (
": "));
106 if(!contStarts && temp.size()>1)
108 StringUtil::replaceFirst(temp.at(1),
"\r",
"");
109 if(temp.at(0)==
"Host")
110 this->setHost(temp.at(1));
111 else if(temp.at(0)==
"User-Agent" || temp.at(0)==
"User-agent")
112 this->setUser_agent(temp.at(1));
113 else if(temp.at(0)==
"Accept")
114 this->setAccept(temp.at(1));
115 else if(temp.at(0)==
"Authorization")
118 if(temp.at(1).find(
"oauth_")!=string::npos)
120 this->getOauthParams(temp.at(1));
123 this->unbase64(temp.at(1));
125 else if(temp.at(0)==
"Accept-Language" || temp.at(0)==
"Accept-language")
128 this->setAccept_lang(temp.at(1));
129 StringUtil::split(lemp, temp.at(1), (
","));
130 for(
unsigned int li=0;li<lemp.size();li++)
132 if(lemp.at(li).find(
";")==string::npos && lemp.at(li)!=
"")
134 string t = lemp.at(li);
135 size_t s = t.find_first_not_of(
" ");
136 size_t e = t.find_last_not_of(
" ")+1;
138 this->localeInfo.push_back(t);
140 else if(lemp.at(li)!=
"")
142 string t = lemp.at(li);
143 size_t s = t.find_first_not_of(
" ");
144 size_t e = t.find(
";");
146 e = t.find_last_not_of(
" ")+1;
148 this->localeInfo.push_back(t);
153 else if(temp.at(0)==
"Accept-Encoding" || temp.at(0)==
"Accept-encoding")
154 this->setAccept_encod(temp.at(1));
155 else if(temp.at(0)==
"Accept-Charset" || temp.at(0)==
"Accept-charset")
156 this->setAccept_lang(temp.at(1));
157 else if(temp.at(0)==
"Keep-Alive" || temp.at(0)==
"Keep-alive")
158 this->setKeep_alive(temp.at(1));
159 else if(temp.at(0)==
"Connection")
160 this->setConnection(temp.at(1));
161 else if(temp.at(0)==
"Cache-Control" || temp.at(0)==
"Cache-control")
162 this->setCache_ctrl(temp.at(1));
163 else if(temp.at(0)==
"Content-Type" || temp.at(0)==
"Content-type")
165 this->setContent_type(temp.at(1));
166 string tempi(temp.at(1));
167 size_t s = tempi.find(
"boundary");
170 this->setContent_type(tempi.substr(0,s));
171 tempi = tempi.substr(s);
173 StringUtil::split(results, tempi, (
"="));
174 if(results.size()==2)
176 string bound =
"--" + results.at(1).substr(0,results.at(1).length());
177 this->setContent_boundary(bound);
181 else if(temp.at(0)==
"Cookie")
185 StringUtil::split(results, temp.at(1), (
"; "));
186 for(
unsigned j=0;j<(int)results.size();j++)
189 StringUtil::split(results1, results.at(j), (
"="));
190 if(results1.size()==2)
191 cookieattrs[results1.at(0)] = results1.at(1);
193 cookieattrs[results1.at(0)] =
"true";
196 else if(temp.at(0)==
"Content-Length" || temp.at(0)==
"Content-length")
197 this->setContent_len(temp.at(1));
198 else if(temp.at(0)==
"Referer")
199 this->setReferer(temp.at(1));
200 else if(temp.at(0)==
"Pragma")
201 this->setPragma(temp.at(1));
203 xtraHeaders[temp.at(0)] = temp.at(1);
208 string tem = temp.at(0);
209 if(!contStarts && tem.find(
"GET")!=string::npos)
211 StringUtil::replaceFirst(tem,
"GET ",
"");
212 this->setMethod(
"GET");
213 StringUtil::split(vemp, tem, (
" "));
216 StringUtil::replaceFirst(vemp.at(1),
"\r",
"");
217 this->setHttpVersion(vemp.at(1));
218 StringUtil::replaceFirst(vemp.at(0),
" ",
"");
219 if(vemp.at(0).find(
"?")!=string ::npos)
222 string valu(vemp.at(0));
223 vemp[0] = valu.substr(0,vemp.at(0).find(
"?"));
224 valu = valu.substr(valu.find(
"?")+1);
226 StringUtil::split(params,valu , (
"&"));
227 map<string ,int> indices;
228 map<string,string>::iterator it;
229 for(
unsigned j=0;j<params.size();j++)
232 StringUtil::split(param, params.at(j), (
"="));
235 string att = param.at(0);
236 StringUtil::replaceFirst(att,
"\r",
"");
237 StringUtil::replaceFirst(att,
"\t",
"");
238 StringUtil::replaceFirst(att,
" ",
"");
240 string attN = CryptoHandler::urlDecode(att);
241 if(attN.find(
"[")!=string::npos && attN.find(
"]")!=string::npos)
243 if(indices.find(attN)==indices.end())
249 indices[attN] = indices[attN] + 1;
251 this->queryParams[attN.substr(0, attN.find(
"[")+1)
252 + CastUtil::lexical_cast<string>(indices[attN])
253 +
"]"] = CryptoHandler::urlDecode(param.at(1));
254 logger << (
"creating array from similar params" + attN.substr(0, attN.find(
"[")+1)
255 + CastUtil::lexical_cast<string>(indices[attN])
257 + CryptoHandler::urlDecode(param.at(1))) << endl;
260 this->setQueryParam(attN,CryptoHandler::urlDecode(param.at(1)));
262 reqorderinf[reqorderinf.size()+1] = att;
266 this->setActUrl(vemp.at(0));
267 memp = StringUtil::split(vemp.at(0), (
"/"));
268 int fs = vemp.at(0).find_first_of(
"/");
269 int es = vemp.at(0).find_last_of(
"/");
272 this->setCntxt_root(path+
"default");
273 this->setCntxt_name(
"default");
274 this->setFile(vemp.at(0).substr(es+1));
275 this->setUrl(path+
"default/"+vemp.at(0));
279 int ss = vemp.at(0).substr(fs+1).find(
"/");
282 this->setCntxt_name(vemp.at(0).substr(fs+1,ss-fs));
283 this->setCntxt_root(path+this->getCntxt_name());
284 this->setFile(vemp.at(0).substr(es+1));
285 this->setUrl(path+vemp.at(0));
290 else if(!contStarts && tem.find(
"HEAD")!=string::npos)
292 StringUtil::replaceFirst(tem,
"HEAD ",
"");
293 this->setMethod(
"HEAD");
294 StringUtil::split(vemp, tem, (
" "));
297 StringUtil::replaceFirst(vemp.at(1),
"\r",
"");
298 this->setHttpVersion(vemp.at(1));
299 StringUtil::replaceFirst(vemp.at(0),
" ",
"");
300 if(vemp.at(0).find(
"?")!=string ::npos)
303 string valu(vemp.at(0));
304 vemp[0] = valu.substr(0,vemp.at(0).find(
"?"));
305 valu = valu.substr(valu.find(
"?")+1);
307 StringUtil::split(params,valu , (
"&"));
308 map<string ,int> indices;
309 map<string,string>::iterator it;
310 for(
unsigned j=0;j<params.size();j++)
313 StringUtil::split(param, params.at(j), (
"="));
316 string att = param.at(0);
317 StringUtil::replaceFirst(att,
"\r",
"");
318 StringUtil::replaceFirst(att,
"\t",
"");
319 StringUtil::replaceFirst(att,
" ",
"");
321 string attN = CryptoHandler::urlDecode(att);
322 if(attN.find(
"[")!=string::npos && attN.find(
"]")!=string::npos)
324 if(indices.find(attN)==indices.end())
330 indices[attN] = indices[attN] + 1;
332 this->queryParams[attN.substr(0, attN.find(
"[")+1)
333 + CastUtil::lexical_cast<string>(indices[attN])
334 +
"]"] = CryptoHandler::urlDecode(param.at(1));
335 logger << (
"creating array from similar params" + attN.substr(0, attN.find(
"[")+1)
336 + CastUtil::lexical_cast<string>(indices[attN])
338 + CryptoHandler::urlDecode(param.at(1))) << endl;
341 this->setQueryParam(attN,CryptoHandler::urlDecode(param.at(1)));
343 reqorderinf[reqorderinf.size()+1] = att;
347 this->setActUrl(vemp.at(0));
348 memp = StringUtil::split(vemp.at(0), (
"/"));
349 int fs = vemp.at(0).find_first_of(
"/");
350 int es = vemp.at(0).find_last_of(
"/");
353 this->setCntxt_root(path+
"default");
354 this->setCntxt_name(
"default");
355 this->setFile(vemp.at(0).substr(es+1));
356 this->setUrl(path+
"default/"+vemp.at(0));
360 int ss = vemp.at(0).substr(fs+1).find(
"/");
363 this->setCntxt_name(vemp.at(0).substr(fs+1,ss-fs));
364 this->setCntxt_root(path+this->getCntxt_name());
365 this->setFile(vemp.at(0).substr(es+1));
366 this->setUrl(path+vemp.at(0));
371 else if(!contStarts && tem.find(
"TRACE")!=string::npos)
373 StringUtil::replaceFirst(tem,
"TRACE ",
"");
374 this->setMethod(
"TRACE");
375 StringUtil::split(vemp, tem, (
" "));
378 StringUtil::replaceFirst(vemp.at(1),
"\r",
"");
379 this->setHttpVersion(vemp.at(1));
380 StringUtil::replaceFirst(vemp.at(0),
" ",
"");
381 if(vemp.at(0).find(
"?")!=string ::npos)
384 string valu(vemp.at(0));
385 vemp[0] = valu.substr(0,vemp.at(0).find(
"?"));
386 valu = valu.substr(valu.find(
"?")+1);
388 StringUtil::split(params,valu , (
"&"));
389 map<string ,int> indices;
390 map<string,string>::iterator it;
391 for(
unsigned j=0;j<params.size();j++)
394 StringUtil::split(param, params.at(j), (
"="));
397 string att = param.at(0);
398 StringUtil::replaceFirst(att,
"\r",
"");
399 StringUtil::replaceFirst(att,
"\t",
"");
400 StringUtil::replaceFirst(att,
" ",
"");
402 string attN = CryptoHandler::urlDecode(att);
403 if(attN.find(
"[")!=string::npos && attN.find(
"]")!=string::npos)
405 if(indices.find(attN)==indices.end())
411 indices[attN] = indices[attN] + 1;
413 this->queryParams[attN.substr(0, attN.find(
"[")+1)
414 + CastUtil::lexical_cast<string>(indices[attN])
415 +
"]"] = CryptoHandler::urlDecode(param.at(1));
416 logger << (
"creating array from similar params" + attN.substr(0, attN.find(
"[")+1)
417 + CastUtil::lexical_cast<string>(indices[attN])
419 + CryptoHandler::urlDecode(param.at(1))) << endl;
422 this->setQueryParam(attN,CryptoHandler::urlDecode(param.at(1)));
424 reqorderinf[reqorderinf.size()+1] = att;
428 this->setActUrl(vemp.at(0));
429 memp = StringUtil::split(vemp.at(0), (
"/"));
430 int fs = vemp.at(0).find_first_of(
"/");
431 int es = vemp.at(0).find_last_of(
"/");
434 this->setCntxt_root(path+
"default");
435 this->setCntxt_name(
"default");
436 this->setFile(vemp.at(0).substr(es+1));
437 this->setUrl(path+
"default/"+vemp.at(0));
441 int ss = vemp.at(0).substr(fs+1).find(
"/");
444 this->setCntxt_name(vemp.at(0).substr(fs+1,ss-fs));
445 this->setCntxt_root(path+this->getCntxt_name());
446 this->setFile(vemp.at(0).substr(es+1));
447 this->setUrl(path+vemp.at(0));
452 else if(!contStarts && tem.find(
"OPTIONS")!=string::npos)
454 StringUtil::replaceFirst(tem,
"OPTIONS ",
"");
455 this->setMethod(
"OPTIONS");
456 StringUtil::split(vemp, tem, (
" "));
459 StringUtil::replaceFirst(vemp.at(1),
"\r",
"");
460 this->setHttpVersion(vemp.at(1));
461 StringUtil::replaceFirst(vemp.at(0),
" ",
"");
462 this->setActUrl(vemp.at(0));
463 memp = StringUtil::split(vemp.at(0), (
"/"));
464 int fs = vemp.at(0).find_first_of(
"/");
465 int es = vemp.at(0).find_last_of(
"/");
468 this->setCntxt_root(path+
"default");
469 this->setCntxt_name(
"default");
470 this->setFile(vemp.at(0).substr(es+1));
471 this->setUrl(path+
"default/"+vemp.at(0));
475 int ss = vemp.at(0).substr(fs+1).find(
"/");
478 this->setCntxt_name(vemp.at(0).substr(fs+1,ss-fs));
479 this->setCntxt_root(path+this->getCntxt_name());
480 this->setFile(vemp.at(0).substr(es+1));
481 this->setUrl(path+vemp.at(0));
486 else if(!contStarts && tem.find(
"DELETE")!=string::npos)
488 StringUtil::replaceFirst(tem,
"DELETE ",
"");
489 this->setMethod(
"DELETE");
490 StringUtil::split(vemp, tem, (
" "));
493 StringUtil::replaceFirst(vemp.at(1),
"\r",
"");
494 this->setHttpVersion(vemp.at(1));
495 StringUtil::replaceFirst(vemp.at(0),
" ",
"");
496 if(vemp.at(0).find(
"?")!=string ::npos)
499 string valu(vemp.at(0));
500 vemp[0] = valu.substr(0,vemp.at(0).find(
"?"));
501 valu = valu.substr(valu.find(
"?")+1);
502 valu = CryptoHandler::urlDecode(valu);
503 StringUtil::split(params,valu, (
"&"));
504 map<string ,int> indices;
505 map<string,string>::iterator it;
506 for(
unsigned j=0;j<params.size();j++)
509 StringUtil::split(param, params.at(j), (
"="));
512 string att = param.at(0);
513 StringUtil::replaceFirst(att,
"\r",
"");
514 StringUtil::replaceFirst(att,
"\t",
"");
515 StringUtil::replaceFirst(att,
" ",
"");
516 string attN = CryptoHandler::urlDecode(att);
517 if(attN.find(
"[")!=string::npos && attN.find(
"]")!=string::npos)
519 if(indices.find(attN)==indices.end())
525 indices[attN] = indices[attN] + 1;
527 this->queryParams[attN.substr(0, attN.find(
"[")+1)
528 + CastUtil::lexical_cast<string>(indices[attN])
529 +
"]"] = CryptoHandler::urlDecode(param.at(1));
530 logger << (
"creating array from similar params" + attN.substr(0, attN.find(
"[")+1)
531 + CastUtil::lexical_cast<string>(indices[attN])
533 + CryptoHandler::urlDecode(param.at(1))) << endl;
536 this->setQueryParam(attN,CryptoHandler::urlDecode(param.at(1)));
537 reqorderinf[reqorderinf.size()+1] = att;
541 this->setActUrl(vemp.at(0));
542 memp = StringUtil::split(vemp.at(0), (
"/"));
543 int fs = vemp.at(0).find_first_of(
"/");
544 int es = vemp.at(0).find_last_of(
"/");
547 this->setCntxt_root(path+
"default");
548 this->setCntxt_name(
"default");
549 this->setFile(vemp.at(0).substr(es+1));
550 this->setUrl(path+
"default/"+vemp.at(0));
554 int ss = vemp.at(0).substr(fs+1).find(
"/");
557 this->setCntxt_name(vemp.at(0).substr(fs+1,ss-fs));
558 this->setCntxt_root(path+this->getCntxt_name());
559 this->setFile(vemp.at(0).substr(es+1));
560 this->setUrl(path+vemp.at(0));
565 else if(!contStarts && tem.find(
"PUT")!=string::npos)
567 StringUtil::replaceFirst(tem,
"PUT ",
"");
568 this->setMethod(
"PUT");
569 StringUtil::split(vemp, tem, (
" "));
572 StringUtil::replaceFirst(vemp.at(1),
"\r",
"");
573 this->setHttpVersion(vemp.at(1));
574 StringUtil::replaceFirst(vemp.at(0),
" ",
"");
575 if(vemp.at(0).find(
"?")!=string ::npos)
578 string valu(vemp.at(0));
579 vemp[0] = valu.substr(0,vemp.at(0).find(
"?"));
580 valu = valu.substr(valu.find(
"?")+1);
581 valu = CryptoHandler::urlDecode(valu);
582 StringUtil::split(params,valu, (
"&"));
583 map<string ,int> indices;
584 map<string,string>::iterator it;
585 for(
unsigned j=0;j<params.size();j++)
588 StringUtil::split(param, params.at(j), (
"="));
591 string att = param.at(0);
592 StringUtil::replaceFirst(att,
"\r",
"");
593 StringUtil::replaceFirst(att,
"\t",
"");
594 StringUtil::replaceFirst(att,
" ",
"");
595 string attN = CryptoHandler::urlDecode(att);
596 if(attN.find(
"[")!=string::npos && attN.find(
"]")!=string::npos)
598 if(indices.find(attN)==indices.end())
604 indices[attN] = indices[attN] + 1;
606 this->queryParams[attN.substr(0, attN.find(
"[")+1)
607 + CastUtil::lexical_cast<string>(indices[attN])
608 +
"]"] = CryptoHandler::urlDecode(param.at(1));
609 logger << (
"creating array from similar params" + attN.substr(0, attN.find(
"[")+1)
610 + CastUtil::lexical_cast<string>(indices[attN])
612 + CryptoHandler::urlDecode(param.at(1))) << endl;
615 this->setQueryParam(attN,CryptoHandler::urlDecode(param.at(1)));
616 reqorderinf[reqorderinf.size()+1] = att;
620 this->setActUrl(vemp.at(0));
621 memp = StringUtil::split(vemp.at(0), (
"/"));
622 int fs = vemp.at(0).find_first_of(
"/");
623 int es = vemp.at(0).find_last_of(
"/");
626 this->setCntxt_root(path+
"default");
627 this->setCntxt_name(
"default");
628 this->setFile(vemp.at(0).substr(es+1));
629 this->setUrl(path+
"default/"+vemp.at(0));
633 int ss = vemp.at(0).substr(fs+1).find(
"/");
636 this->setCntxt_name(vemp.at(0).substr(fs+1,ss-fs));
637 this->setCntxt_root(path+this->getCntxt_name());
638 this->setFile(vemp.at(0).substr(es+1));
639 this->setUrl(path+vemp.at(0));
644 else if(!contStarts && tem.find(
"POST")!=string::npos)
646 StringUtil::replaceFirst(tem,
"POST ",
"");
647 this->setMethod(
"POST");
648 StringUtil::split(vemp, tem, (
" "));
653 StringUtil::replaceFirst(vemp.at(1),
"\r",
"");
654 this->setHttpVersion(vemp.at(1));
655 StringUtil::replaceFirst(vemp.at(0),
" ",
"");
656 if(vemp.at(0).find(
"?")!=string ::npos)
659 string valu(vemp.at(0));
660 vemp[0] = valu.substr(0,vemp.at(0).find(
"?"));
661 valu = valu.substr(valu.find(
"?")+1);
662 valu = CryptoHandler::urlDecode(valu);
663 StringUtil::split(params,valu, (
"&"));
664 map<string ,int> indices;
665 map<string,string>::iterator it;
666 for(
unsigned j=0;j<params.size();j++)
669 StringUtil::split(param, params.at(j), (
"="));
672 string att = param.at(0);
673 StringUtil::replaceFirst(att,
"\r",
"");
674 StringUtil::replaceFirst(att,
"\t",
"");
675 StringUtil::replaceFirst(att,
" ",
"");
676 string attN = CryptoHandler::urlDecode(att);
677 if(attN.find(
"[")!=string::npos && attN.find(
"]")!=string::npos)
679 if(indices.find(attN)==indices.end())
685 indices[attN] = indices[attN] + 1;
687 this->queryParams[attN.substr(0, attN.find(
"[")+1)
688 + CastUtil::lexical_cast<string>(indices[attN])
689 +
"]"] = CryptoHandler::urlDecode(param.at(1));
690 logger << (
"creating array from similar params" + attN.substr(0, attN.find(
"[")+1)
691 + CastUtil::lexical_cast<string>(indices[attN])
693 + CryptoHandler::urlDecode(param.at(1))) << endl;
696 this->setQueryParam(attN,CryptoHandler::urlDecode(param.at(1)));
697 reqorderinf[reqorderinf.size()+1] = att;
701 this->setActUrl(vemp.at(0));
702 memp = StringUtil::split(vemp.at(0), (
"/"));
703 int fs = vemp.at(0).find_first_of(
"/");
704 int es = vemp.at(0).find_last_of(
"/");
707 this->setCntxt_root(path+
"default");
708 this->setCntxt_name(
"default");
709 this->setFile(vemp.at(0).substr(es+1));
710 this->setUrl(path+
"default/"+vemp.at(0));
714 int ss = vemp.at(0).substr(fs+1).find(
"/");
717 this->setCntxt_name(vemp.at(0).substr(fs+1,ss-fs));
718 this->setCntxt_root(path+this->getCntxt_name());
719 this->setFile(vemp.at(0).substr(es+1));
720 this->setUrl(path+vemp.at(0));
734 conten.append(vec.at(i));
741 this->setContent(conten);
767 if(this->getContent()!=
"")
770 if(this->getContent_type().find(
"application/x-www-form-urlencoded")!=string::npos)
773 string valu(this->getContent());
774 StringUtil::split(params,valu , (
"&"));
775 map<string ,int> indices;
776 map<string,string>::iterator it;
777 for(
unsigned j=0;j<params.size();j++)
780 StringUtil::split(param, params.at(j), (
"="));
783 string att = param.at(0);
784 StringUtil::replaceFirst(att,
"\r",
"");
785 StringUtil::replaceFirst(att,
"\t",
"");
786 StringUtil::replaceFirst(att,
" ",
"");
787 string attN = CryptoHandler::urlDecode(att);
788 if(attN.find(
"[")!=string::npos && attN.find(
"]")!=string::npos)
790 if(indices.find(attN)==indices.end())
796 indices[attN] = indices[attN] + 1;
798 this->requestParams[attN.substr(0, attN.find(
"[")+1)
799 + CastUtil::lexical_cast<string>(indices[attN])
800 +
"]"] = CryptoHandler::urlDecode(param.at(1));
801 logger << (
"creating array from similar params" + attN.substr(0, attN.find(
"[")+1)
802 + CastUtil::lexical_cast<string>(indices[attN])
804 + CryptoHandler::urlDecode(param.at(1))) << endl;
807 this->setRequestParam(attN,CryptoHandler::urlDecode(param.at(1)));
808 reqorderinf[reqorderinf.size()+1] = att;
812 else if(this->getContent()!=
"" && this->getContent_boundary()!=
"")
814 string delb =
"\r"+this->getContent_boundary();
815 string delend =
"\r"+this->getContent_boundary()+
"--";
816 size_t stb = this->getContent().find_first_of(delb)+delb.length()+1;
818 string param_conts = this->getContent().substr(stb);
819 StringUtil::replaceFirst(param_conts,delend,
"");
820 param_conts = param_conts.substr(0,param_conts.length()-1);
822 StringUtil::split(parameters, param_conts, (delb));
827 map<string ,int> indices;
828 map<string,string>::iterator it;
829 for(
unsigned j=0;j<parameters.size();j++)
831 if(parameters.at(j)==
"" || parameters.at(j).find_first_not_of(
" ")==string::npos
832 || parameters.at(j).find_first_not_of(
"\r")==string::npos)
835 string parm = parameters.at(j);
837 size_t dis = parm.find(
"Content-Disposition: ");
838 if(dis==string::npos)
839 dis = parm.find(
"Content-disposition: ");
840 string cont_disp,cont_type;
841 if(dis!=string::npos)
843 size_t dist = parm.find(
"Content-Type: ");
844 if(dist==string::npos)
845 dist = parm.find(
"Content-yype: ");
847 if(dist==string::npos)
849 dist = parm.find(
"\r\r");
856 cont_type = parm.substr(dist+14,parm.find(
"\r\r")-(dist+14));
857 dise = parm.find(
"\r\r") + 2;
861 cont_disp = parm.substr(dis+21,dist-(dis+21));
862 StringUtil::replaceFirst(cont_disp,
"\r",
"");
865 parm = parm.substr(dise);
868 StringUtil::split(parmdef, cont_disp, (
";"));
870 for(
unsigned k=0;k<parmdef.size();k++)
872 if(parmdef.at(k)!=
"" && parmdef.at(k).find(
"=")!=string::npos)
874 size_t stpd = parmdef.at(k).find_first_not_of(
" ");
875 size_t enpd = parmdef.at(k).find_last_not_of(
" ");
878 string propert = parmdef.at(k).substr(stpd,enpd-stpd+1);
880 StringUtil::split(proplr, propert, (
"="));
883 if(proplr.at(0)==
"name" && proplr.at(1)!=
"\"\"")
886 key = key.substr(key.find_first_not_of(
"\""),key.find_last_not_of(
"\"")-key.find_first_not_of(
"\"")+1);
887 key = CryptoHandler::urlDecode(key);
888 StringUtil::replaceFirst(cont_type,
"\r",
"");
889 datf.type = cont_type;
892 else if(proplr.at(0)==
"filename" && proplr.at(1)!=
"\"\"")
894 string fna = proplr.at(1);
895 fna = fna.substr(fna.find_first_not_of(
"\""),fna.find_last_not_of(
"\"")-fna.find_first_not_of(
"\"")+1);
896 fna = CryptoHandler::urlDecode(fna);
904 string attN = CryptoHandler::urlDecode(key);
905 if(attN.find(
"[")!=string::npos && attN.find(
"]")!=string::npos)
907 if(indices.find(attN)==indices.end())
913 indices[attN] = indices[attN] + 1;
915 this->requestParamsF[attN.substr(0, attN.find(
"[")+1)
916 + CastUtil::lexical_cast<string>(indices[attN])
918 logger << (
"creating array from similar params" + attN.substr(0, attN.find(
"[")+1)
919 + CastUtil::lexical_cast<string>(indices[attN])
921 + datf.fileName) << endl;
923 this->setRequestParamF(attN,datf);
924 if(datf.fileName!=
"")
926 string tmpfile = this->getCntxt_root() +
"/temp/"+ this->getContent_boundary() +datf.value;
928 os.open(tmpfile.c_str());
929 os.write(datf.value.c_str(), datf.value.length());
931 datf.tmpFileName = tmpfile;
932 datf.length = datf.value.length();
934 string hr = (key +
" " + datf.type +
" "+ datf.fileName+
" "+ datf.value);
945 string HttpRequest::buildRequest(
const char *keyc,
const char *valuec)
953 this->setHost(value);
954 else if(key==
"User-Agent" || key==
"User-agent")
955 this->setUser_agent(value);
956 else if(key==
"Accept")
957 this->setAccept(value);
958 else if(key==
"Accept-Language" || key==
"Accept-language")
961 this->setAccept_lang(value);
962 StringUtil::split(lemp, value, (
","));
963 for(
unsigned int li=0;li<lemp.size();li++)
965 if(lemp.at(li).find(
";")==string::npos && lemp.at(li)!=
"")
967 string t = lemp.at(li);
968 size_t s = t.find_first_not_of(
" ");
969 size_t e = t.find_last_not_of(
" ")+1;
971 this->localeInfo.push_back(t);
973 else if(lemp.at(li)!=
"")
975 string t = lemp.at(li);
976 size_t s = t.find_first_not_of(
" ");
977 size_t e = t.find(
";");
979 e = t.find_last_not_of(
" ")+1;
981 this->localeInfo.push_back(t);
986 else if(key==
"Accept-Encoding" || key==
"Accept-encoding")
987 this->setAccept_encod(value);
988 else if(key==
"Accept-Charset" || key==
"Accept-charset")
989 this->setAccept_lang(value);
990 else if(key==
"Keep-Alive" || key==
"Keep-alive")
991 this->setKeep_alive(value);
992 else if(key==
"Connection")
993 this->setConnection(value);
994 else if(key==
"Cache-Control" || key==
"Cache-control")
995 this->setCache_ctrl(value);
996 else if(key==
"Content-Type" || key==
"Content-type")
998 this->setContent_type(value);
1000 size_t s = tempi.find(
"boundary");
1003 this->setContent_type(tempi.substr(0,s));
1004 tempi = tempi.substr(s);
1006 StringUtil::split(results, tempi, (
"="));
1007 if(results.size()==2)
1009 string bound =
"--" + results.at(1).substr(0,results.at(1).length());
1010 this->setContent_boundary(bound);
1014 else if(key==
"Content" && value!=
"")
1016 if((this->getContent_type().find(
"application/soap+xml")!=string::npos || this->getContent_type().find(
"text/xml")!=string::npos))
1018 value = value.substr(0,value.find_last_of(
">")+1);
1019 if(value.find(
"<?")!=string::npos && value.find(
"?>")!=string::npos)
1021 value = value.substr(value.find(
"?>")+2);
1023 this->setContent(value);
1025 else if(this->getContent_type().find(
"application/x-www-form-urlencoded")!=string::npos)
1028 StringUtil::split(params,value , (
"&"));
1029 for(
unsigned j=0;j<params.size();j++)
1032 StringUtil::split(param, params.at(j), (
"="));
1035 string att = param.at(0);
1036 StringUtil::replaceFirst(att,
"\r",
"");
1037 StringUtil::replaceFirst(att,
"\t",
"");
1038 StringUtil::replaceFirst(att,
" ",
"");
1039 this->setRequestParam(att,param.at(1));
1045 size_t rn = value.find_first_of(
"\r\n");
1046 string h = CastUtil::lexical_cast<
string>((int)rn);
1048 string boundary = this->getContent_boundary();
1049 fprintf(stderr,boundary.c_str());
1050 fprintf(stderr,value.c_str());
1054 string delb = boundary+
"\r\n";
1055 string delend = boundary+
"--\r\n";
1056 size_t stb = value.find_first_of(delb)+delb.length();
1057 size_t enb = value.find_last_not_of(delend);
1058 h = CastUtil::lexical_cast<
string>((int)stb)+
" "+CastUtil::lexical_cast<
string>((int)enb);
1060 string param_conts = value.substr(stb,enb-stb-2);
1062 StringUtil::replaceFirst(value,delb,
"");
1063 StringUtil::replaceFirst(value,delend,
"");
1065 StringUtil::split(parameters, value, (delb));
1066 retval =
"Boundary: "+ boundary +
"\nLength: " ;
1067 retval += CastUtil::lexical_cast<
string>((int)value.length()) +
"\nStart End: "
1068 + CastUtil::lexical_cast<string>((
int)stb) + " " +
CastUtil::lexical_cast<
string>((
int)enb) +"\n";
1070 for(
unsigned j=0;j<parameters.size();j++)
1072 if(parameters.at(j)==
"" || parameters.at(j).find_first_not_of(
" ")==string::npos
1073 || parameters.at(j).find_first_not_of(
"\r\n")==string::npos)
1075 fprintf(stderr,parameters.at(j).c_str());
1078 string parm = parameters.at(j);
1079 retval+= parm +
"\nparm";
1080 size_t dis = parm.find(
"Content-Disposition: ");
1081 if(dis==string::npos)
1082 dis = parm.find(
"Content-disposition: ");
1083 string cont_disp,cont_type;
1084 if(dis!=string::npos)
1086 size_t dist = parm.find(
"Content-Type: ");
1087 if(dist==string::npos)
1088 dist = parm.find(
"Content-type: ");
1090 if(dist==string::npos)
1092 dist = parm.find(
"\r\n\r\n");
1097 cont_type = parm.substr(dist+14,parm.find(
"\r\n\r\n")-(dist+14));
1098 dise = parm.find(
"\r\n\r\n") + 4;
1100 cont_disp = parm.substr(dis+21,dist-(dis+21));
1101 StringUtil::replaceFirst(cont_disp,
"\r\n",
"");
1102 retval+=
"\ncdisp = " + cont_disp;
1103 retval+=
"\ndise = " + CastUtil::lexical_cast<
string>((int)dise);
1104 parm = parm.substr(dise);
1105 parm = parm.substr(0,parm.length()-1);
1108 StringUtil::split(parmdef, cont_disp, (
";"));
1110 for(
unsigned k=0;k<parmdef.size();k++)
1112 if(parmdef.at(k)!=
"" && parmdef.at(k).find(
"=")!=string::npos)
1114 size_t stpd = parmdef.at(k).find_first_not_of(
" ");
1115 size_t enpd = parmdef.at(k).find_last_not_of(
" ");
1116 retval+=
"\nparmdef = " + parmdef.at(k) ;
1117 retval+=
"\nst en = " + CastUtil::lexical_cast<
string>((int)stpd) +
" " + CastUtil::lexical_cast<
string>((int)enpd);
1118 string propert = parmdef.at(k).substr(stpd,enpd-stpd+1);
1120 StringUtil::split(proplr, propert, (
"="));
1121 if(proplr.size()==2)
1123 if(proplr.at(0)==
"name" && proplr.at(1)!=
"\"\"")
1126 key = key.substr(key.find_first_not_of(
"\""),key.find_last_not_of(
"\"")-key.find_first_not_of(
"\"")+1);
1127 datf.type = cont_type;
1130 else if(proplr.at(0)==
"filename" && proplr.at(1)!=
"\"\"")
1132 string fna = proplr.at(1);
1133 fna = fna.substr(fna.find_first_not_of(
"\""),fna.find_last_not_of(
"\"")-fna.find_first_not_of(
"\"")+1);
1134 datf.fileName = fna;
1141 this->setRequestParamF(key,datf);
1142 retval+= (key +
" " + datf.type +
" "+ datf.fileName+
" "+ datf.value);
1148 else if(key==
"Content-Length" || key==
"Content-length")
1149 this->setContent_len(value);
1150 else if(key==
"Referer")
1151 this->setReferer(value);
1152 else if(key==
"Pragma")
1153 this->setPragma(value);
1154 else if(key==
"Method")
1155 this->setMethod(value);
1156 else if(key==
"HttpVersion")
1157 this->setHttpVersion(value);
1158 else if(key==
"GetArguments")
1161 StringUtil::split(params, value, (
"&"));
1162 for(
unsigned j=0;j<params.size();j++)
1165 StringUtil::split(param, params.at(j), (
"="));
1168 string att = param.at(0);
1169 StringUtil::replaceFirst(att,
"\r",
"");
1170 StringUtil::replaceFirst(att,
"\t",
"");
1171 StringUtil::replaceFirst(att,
" ",
"");
1172 this->setQueryParam(att,param.at(1));
1194 else if(key.find(
"URL")!=string::npos)
1196 StringUtil::replaceFirst(key,
"URL",
"");
1198 this->setActUrl(value);
1199 StringUtil::split(memp, value, (
"/"));
1200 int fs = value.find_first_of(
"/");
1201 int es = value.find_last_of(
"/");
1204 this->setCntxt_root(key+
"default");
1205 this->setCntxt_name(
"default");
1206 this->setFile(value.substr(es+1));
1207 this->setUrl(key+
"default/"+value);
1211 int ss = value.substr(fs+1).find(
"/");
1214 this->setCntxt_name(value.substr(fs+1,ss-fs));
1215 this->setCntxt_root(key+this->getCntxt_name());
1216 this->setFile(value.substr(es+1));
1217 this->setUrl(key+value);
1222 xtraHeaders[key] = value;
1226 string HttpRequest::toString()
1229 ret =
"\nHost: "+this->getHost();
1230 ret +=
"\nAccept: "+this->getAccept();
1231 ret +=
"\nAccept Chars: "+this->getAccept_chars();
1232 ret +=
"\nAccept Encoding: "+this->getAccept_encod();
1233 ret +=
"\nAccept Language: "+this->getAccept_lang();
1234 ret +=
"\nCache Ctrl: "+this->getCache_ctrl();
1235 ret +=
"\nConnection: "+this->getConnection();
1236 ret +=
"\nContent: "+this->getContent();
1237 ret +=
"\nContent Length: "+this->getContent_len();
1238 ret +=
"\nContent Type: "+this->getContent_type();
1239 ret +=
"\nHttp Version: "+this->getHttpVersion();
1240 ret +=
"\nMethod: "+this->getMethod();
1241 ret +=
"\nUser agent: "+this->getUser_agent();
1242 ret +=
"\nUrl: "+this->getUrl();
1243 ret +=
"\nFile: "+this->getFile();
1244 ret +=
"\nContext Name: "+this->getCntxt_name();
1245 ret +=
"\nContext Root: "+this->getCntxt_root();
1246 ret +=
"\nDefault Locale: "+this->getDefaultLocale();
1247 ret +=
"\nContent Boundary: "+this->getContent_boundary();
1249 if(this->requestParams.size()>0)
1251 RMap::iterator iter;
1252 for (iter=this->requestParams.begin();iter!=this->requestParams.end();iter++)
1254 vals+= (
"\nKey: "+iter->first +
" Value: "+iter->second);
1257 if(this->requestParamsF.size()>0)
1259 FMap::iterator iter;
1260 for (iter=this->requestParamsF.begin();iter!=this->requestParamsF.end();iter++)
1263 vals+= (
"\nKey: "+iter->first +
" Type: "+dat.type +
" FileName: "+dat.fileName);
1264 vals+= (
"\nValue: "+dat.value);
1267 ret +=
"\nRequest Parameters "+vals;
1272 HttpRequest::~HttpRequest()
1276 string HttpRequest::getMethod()
const
1281 void HttpRequest::setMethod(
string method)
1283 this->method = method;
1286 string HttpRequest::getUser_agent()
const
1291 void HttpRequest::setUser_agent(
string user_agent)
1293 this->user_agent = user_agent;
1296 string HttpRequest::getAccept()
const
1301 void HttpRequest::setAccept(
string accept)
1303 this->accept = accept;
1306 string HttpRequest::getAccept_lang()
const
1311 void HttpRequest::setAccept_lang(
string accept_lang)
1313 this->accept_lang = accept_lang;
1316 string HttpRequest::getAccept_encod()
const
1318 return accept_encod;
1321 void HttpRequest::setAccept_encod(
string accept_encod)
1323 this->accept_encod = accept_encod;
1326 string HttpRequest::getAccept_chars()
const
1328 return accept_chars;
1331 void HttpRequest::setAccept_chars(
string accept_chars)
1333 this->accept_chars = accept_chars;
1336 string HttpRequest::getKeep_alive()
const
1341 void HttpRequest::setKeep_alive(
string keep_alive)
1343 this->keep_alive = keep_alive;
1346 string HttpRequest::getConnection()
const
1351 void HttpRequest::setConnection(
string connection)
1353 this->connection = connection;
1356 string HttpRequest::getCache_ctrl()
const
1361 void HttpRequest::setCache_ctrl(
string cache_ctrl)
1363 this->cache_ctrl = cache_ctrl;
1366 Map HttpRequest::getAttributes()
const
1371 void HttpRequest::setAttributes(Map attributes)
1373 this->attributes = attributes;
1376 string HttpRequest::getAttribute(
string key)
1378 return attributes[key];
1381 void HttpRequest::setAttribute(
string key,
string value)
1383 this->attributes[key] = value;
1388 return &(this->session);
1392 this->session = session;
1395 string HttpRequest::getHost()
const
1399 void HttpRequest::setHost(
string host)
1404 void HttpRequest::setUrl(
string url)
1406 StringUtil::replaceFirst(url,
"//",
"/");
1410 string HttpRequest::getUrl()
1415 void HttpRequest::setHttpVersion(
string httpVersion)
1417 this->httpVersion = httpVersion;
1419 string HttpRequest::getHttpVersion()
1421 return this->httpVersion;
1424 string HttpRequest::getContent_type()
const
1426 return content_type;
1429 void HttpRequest::setContent_type(
string content_type)
1431 this->content_type = content_type;
1434 string HttpRequest::getContent_boundary()
const
1436 return content_boundary;
1439 void HttpRequest::setContent_boundary(
string content_boundary)
1441 this->content_boundary = content_boundary;
1444 string HttpRequest::getContent_len()
const
1449 void HttpRequest::setContent_len(
string content_len)
1451 this->content_len = content_len;
1454 string HttpRequest::getContent()
const
1459 void HttpRequest::setContent(
string content)
1461 this->content = content;
1464 string HttpRequest::getReferer()
const
1469 void HttpRequest::setReferer(
string referer)
1471 this->referer = referer;
1474 string HttpRequest::getPragma()
const
1479 void HttpRequest::setPragma(
string pragma)
1481 this->pragma = pragma;
1484 RMap HttpRequest::getRequestParams()
const
1486 return requestParams;
1489 void HttpRequest::setRequestParams(RMap requestParams)
1491 this->requestParams = requestParams;
1494 string HttpRequest::getRequestParam(
string key)
1496 if(this->requestParams.find(key)!=this->requestParams.end())
1497 return this->requestParams[key];
1498 else if(this->requestParamsF.find(key)!=this->requestParamsF.end())
1499 return this->requestParamsF[key].value;
1504 string HttpRequest::getRequestParamType(
string key)
1506 if(this->requestParamsF.find(key)!=this->requestParamsF.end())
1507 return this->requestParamsF[key].type;
1512 void HttpRequest::setRequestParam(
string key,
string value)
1514 this->requestParams[key] = value;
1517 void HttpRequest::setRequestParamF(
string key,
FormData value)
1519 this->requestParamsF[key] = value;
1522 string HttpRequest::getCntxt_root()
const
1527 void HttpRequest::setCntxt_root(
string cntxt_root)
1529 this->cntxt_root = cntxt_root;
1531 string HttpRequest::getDefaultLocale()
1533 if(this->localeInfo.size()>0)
1534 return this->localeInfo.at(0);
1538 string HttpRequest::getCntxt_name()
const
1543 void HttpRequest::setCntxt_name(
string cntxt_name)
1545 this->cntxt_name = cntxt_name;
1548 string HttpRequest::getFile()
const
1553 void HttpRequest::setFile(
string file)
1556 if(this->file!=
"" && this->url.find(this->file)!=string::npos
1557 && this->url.find(
"/")!=string::npos)
1560 this->url = this->url.substr(0, this->url.find_last_of(
"/")+1) + file;
1564 this->url +=
"/" + file;
1569 string HttpRequest::getActUrl()
const
1574 void HttpRequest::setActUrl(
string actUrl)
1576 this->actUrl = actUrl;
1579 map<string,string> HttpRequest::getAuthinfo()
const
1584 void HttpRequest::setAuthinfo(map<string,string> authinfo)
1586 this->authinfo = authinfo;
1589 string HttpRequest::toPHPVariablesString(
string def)
1592 ret =
"<?php\n$_SERVER['HTTP_HOST'] = '"+this->getHost();
1593 ret +=
"';\n$_SERVER['HTTP_ACCEPT'] = '"+this->getAccept();
1594 ret +=
"';\n$_SERVER['HTTP_ACCEPT_CHARSET'] = '"+this->getAccept_chars();
1595 ret +=
"';\n$_SERVER['HTTP_ACCEPT_ENCODING'] = '"+this->getAccept_encod();
1596 ret +=
"';\n$_SERVER['HTTP_ACCEPT_LANGUAGE'] = '"+this->getAccept_lang();
1597 ret +=
"';\n$_SERVER_EX['CACHE_CNTRL'] = '"+this->getCache_ctrl();
1598 ret +=
"';\n$_SERVER['HTTP_CONNECTION'] = '"+this->getConnection();
1599 ret +=
"';\n$_SERVER_EX['HTTP_CONTENT'] = '"+this->getContent();
1600 ret +=
"';\n$_SERVER_EX['HTTP_CNTENT_LENGTH'] = '"+this->getContent_len();
1601 ret +=
"';\n$_SERVER_EX['HTTP_CNTENT_TYPE'] = '"+this->getContent_type();
1602 ret +=
"';\n$_SERVER_EX['HTTP_VERSION'] = '"+this->getHttpVersion();
1603 ret +=
"';\n$_SERVER['REQUEST_METHOD'] = '"+this->getMethod();
1604 ret +=
"';\n$_SERVER['HTTP_USER_AGENT'] = '"+this->getUser_agent();
1605 string requri = this->getActUrl();
1606 StringUtil::replaceFirst(requri, (
"/"+this->getCntxt_name()),
"");
1609 ret +=
"';\n$_SERVER['REQUEST_URI'] = '"+requri;
1610 ret +=
"';\n$_SERVER_EX['HTTP_REQ_FILE'] = '"+this->getFile();
1611 ret +=
"';\n$_SERVER_EX['CONTEXT_NAME'] = '"+this->getCntxt_name();
1613 ret +=
"';\n$_SERVER['DOCUMENT_ROOT'] = '"+this->getCntxt_root();
1615 ret +=
"';\n$_SERVER['DOCUMENT_ROOT'] = '/"+this->getCntxt_name();
1616 ret +=
"';\n$_SERVER_EX['DEFAULT_LOCALE'] = '"+this->getDefaultLocale();
1617 ret +=
"';\n$_SERVER['HTTP_HOST'] = '"+this->getContent_boundary() +
"';\n";
1618 if(this->queryParams.size()>0)
1620 RMap::iterator iter;
1621 for (iter=this->queryParams.begin();iter!=this->queryParams.end();iter++)
1623 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1625 ret +=
"\nif(!isset($_GET['"+iter->first.substr(0, iter->first.find(
"["))+
"']))\n{\n$_GET['"+iter->first.substr(0, iter->first.find(
"["))+
"']=array();\n}\n";
1626 ret += (
"\n$_GET['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1627 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"';");
1630 ret +=
"\n$_GET['"+iter->first+
"'] = '"+ iter->second +
"';";
1633 if(this->requestParams.size()>0)
1635 RMap::iterator iter;
1636 for (iter=this->requestParams.begin();iter!=this->requestParams.end();iter++)
1638 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1640 ret +=
"\nif(!isset($_POST['"+iter->first.substr(0, iter->first.find(
"["))+
"']))\n{\n$_POST['"+iter->first.substr(0, iter->first.find(
"["))+
"']=array();\n}\n";
1641 ret += (
"\n$_POST['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1642 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"';");
1645 ret +=
"\n$_POST['"+iter->first+
"'] = '"+iter->second +
"';";
1648 if(this->requestParamsF.size()>0)
1650 FMap::iterator iter;
1651 for (iter=this->requestParamsF.begin();iter!=this->requestParamsF.end();iter++)
1654 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1656 ret +=
"\nif(!isset($_FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']))\n{\n$_FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']=array()\n}\n";
1657 ret +=
"\nif(!isset($_FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']"+iter->first.substr(iter->first.find(
"["))+
"))\n"
1658 +
"{\n$_FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']"+iter->first.substr(iter->first.find(
"["))+
"=array();\n}\n";
1659 ret +=
"\n$_FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1660 iter->first.substr(iter->first.find(
"[")) +
"['name'] = '"+ dat.fileName +
"';";
1661 ret +=
"\n$_FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1662 iter->first.substr(iter->first.find(
"[")) +
"['type'] = '"+ dat.type +
"';";
1663 ret +=
"\n$_FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1664 iter->first.substr(iter->first.find(
"[")) +
"['size'] = "+ CastUtil::lexical_cast<string>(dat.length) +
";";
1665 ret +=
"\n$_FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1666 iter->first.substr(iter->first.find(
"[")) +
"['tmp_name'] = '"+ dat.tmpFileName +
"';";
1667 ret +=
"\n$_FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1668 iter->first.substr(iter->first.find(
"[")) +
"['error'] = 0;";
1672 ret +=
"\nif(!isset($_FILES['"+iter->first+
"']))\n{\n$_FILES['"+iter->first+
"']=array();\n}\n";
1673 ret +=
"\n$_FILES['"+iter->first+
"']['name'] = '"+ dat.fileName +
"';";
1674 ret +=
"\n$_FILES['"+iter->first+
"']['type'] = '"+ dat.type +
"';";
1675 ret +=
"\n$_FILES['"+iter->first+
"']['size'] = "+ CastUtil::lexical_cast<
string>(dat.length) +
";";
1676 ret +=
"\n$_FILES['"+iter->first+
"']['tmp_name'] = '"+ dat.tmpFileName +
"';";
1677 ret +=
"\n$_FILES['"+iter->first+
"']['error'] = 0;";
1682 ret +=
"\ninclude_once('"+this->getUrl()+
"');";
1684 ret +=
"\ninclude_once('"+def+
"');";
1689 string HttpRequest::toPerlVariablesString()
1692 ret +=
"$_SERVER = {};";
1693 ret +=
"\n$_SERVER_EX = {};";
1694 ret +=
"\n$_GET = {};";
1695 ret +=
"\n$_POST = {};";
1696 ret +=
"\n$_FILES = {};";
1697 ret +=
"\n$_SERVER{'HTTP_HOST'} = '"+this->getHost();
1698 ret +=
"';\n$_SERVER{'HTTP_ACCEPT'} = '"+this->getAccept();
1699 ret +=
"';\n$_SERVER{'HTTP_ACCEPT_CHARSET'} = '"+this->getAccept_chars();
1700 ret +=
"';\n$_SERVER{'HTTP_ACCEPT_ENCODING'} = '"+this->getAccept_encod();
1701 ret +=
"';\n$_SERVER{'HTTP_ACCEPT_LANGUAGE'} = '"+this->getAccept_lang();
1702 ret +=
"';\n$_SERVER_EX{'CACHE_CNTRL'} = '"+this->getCache_ctrl();
1703 ret +=
"';\n$_SERVER{'HTTP_CONNECTION'} = '"+this->getConnection();
1704 ret +=
"';\n$_SERVER_EX{'HTTP_CONTENT'} = '"+this->getContent();
1705 ret +=
"';\n$_SERVER_EX{'HTTP_CNTENT_LENGTH'} = '"+this->getContent_len();
1706 ret +=
"';\n$_SERVER_EX{'HTTP_CNTENT_TYPE'} = '"+this->getContent_type();
1707 ret +=
"';\n$_SERVER_EX{'HTTP_VERSION'} = '"+this->getHttpVersion();
1708 ret +=
"';\n$_SERVER{'REQUEST_METHOD'} = '"+this->getMethod();
1709 ret +=
"';\n$_SERVER{'HTTP_USER_AGENT'} = '"+this->getUser_agent();
1710 ret +=
"';\n$_SERVER{'REQUEST_URI'} = '"+this->getUrl();
1711 ret +=
"';\n$_SERVER_EX{'HTTP_REQ_FILE'} = '"+this->getFile();
1712 ret +=
"';\n$_SERVER_EX{'CONTEXT_NAME'} = '"+this->getCntxt_name();
1713 ret +=
"';\n$_SERVER{'DOCUMENT_ROOT'} = '"+this->getCntxt_root();
1714 ret +=
"';\n$_SERVER_EX{'DEFAULT_LOCALE'} = '"+this->getDefaultLocale();
1715 ret +=
"';\n$_SERVER{'HTTP_HOST'} = '"+this->getContent_boundary() +
"';\n";
1716 if(this->queryParams.size()>0)
1718 RMap::iterator iter;
1719 for (iter=this->queryParams.begin();iter!=this->queryParams.end();iter++)
1721 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1723 string key = iter->first;
1724 StringUtil::replaceFirst(key,
"[",
"{");
1725 StringUtil::replaceFirst(key,
"]",
"}");
1726 ret +=
"\nif(!exists $_GET{'"+key.substr(0, key.find(
"{"))+
"'})\n{\n$_GET{'"+key.substr(0, key.find(
"{"))+
"'}={}\n}\n";
1727 ret += (
"\n$_GET{'"+key.substr(0, key.find(
"{"))+
"'}" +
1728 key.substr(key.find(
"{")) +
" = '"+iter->second +
"';");
1731 ret +=
"\n$_GET{'"+iter->first+
"'} = '"+ iter->second +
"';";
1734 if(this->requestParams.size()>0)
1736 RMap::iterator iter;
1737 for (iter=this->requestParams.begin();iter!=this->requestParams.end();iter++)
1739 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1741 string key = iter->first;
1742 StringUtil::replaceFirst(key,
"[",
"{");
1743 StringUtil::replaceFirst(key,
"]",
"}");
1744 ret +=
"\nif(!exists $_POST{'"+key.substr(0, key.find(
"{"))+
"'})\n{\n$_POST{'"+key.substr(0, key.find(
"{"))+
"'}={}\n}\n";
1745 ret += (
"\n$_POST{'"+key.substr(0, key.find(
"{"))+
"'}" +
1746 key.substr(key.find(
"{")) +
" = '"+iter->second +
"';");
1749 ret +=
"\n$_POST{'"+iter->first+
"'} = '"+iter->second +
"';";
1752 if(this->requestParamsF.size()>0)
1754 FMap::iterator iter;
1755 for (iter=this->requestParamsF.begin();iter!=this->requestParamsF.end();iter++)
1758 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1760 string key = iter->first;
1761 StringUtil::replaceFirst(key,
"[",
"{");
1762 StringUtil::replaceFirst(key,
"]",
"}");
1763 ret +=
"\nif(!exists $_FILES{'"+key.substr(0, key.find(
"{"))+
"'})\n{\n$_FILES{'"+key.substr(0, key.find(
"{"))+
"'}={}\n}\n";
1764 ret +=
"\nif(!exists $_FILES{'"+key.substr(0, key.find(
"{"))+
"'}{'"+key.substr(key.find(
"{"))+
"'})\n"
1765 +
"{\n$_FILES{'"+key.substr(0, key.find(
"{"))+
"'}{'"+key.substr(key.find(
"{"))+
"'}={}\n}\n";
1766 ret +=
"\n$_FILES{'"+key.substr(0, key.find(
"{"))+
"'}" +
1767 key.substr(key.find(
"{")) +
"{'name'} = '"+ dat.fileName +
"';";
1768 ret +=
"\n$_FILES{'"+key.substr(0, key.find(
"{"))+
"'}" +
1769 key.substr(key.find(
"{")) +
"{'type'} = '"+ dat.type +
"';";
1770 ret +=
"\n$_FILES{'"+key.substr(0, key.find(
"{"))+
"'}" +
1771 key.substr(key.find(
"{")) +
"{'size'} = "+ CastUtil::lexical_cast<string>(dat.length) +
";";
1772 ret +=
"\n$_FILES{'"+key.substr(0, key.find(
"{"))+
"'}" +
1773 key.substr(key.find(
"{")) +
"{'tmp_name'} = '"+ dat.tmpFileName +
"';";
1774 ret +=
"\n$_FILES{'"+key.substr(0, key.find(
"{"))+
"'}" +
1775 key.substr(key.find(
"{")) +
"{'error'} = 0;";
1779 ret +=
"\nif(!exists $_FILES{'"+iter->first+
"'})\n{\n$_FILES{'"+iter->first+
"'}={}\n}\n";
1780 ret +=
"\n$_FILES{'"+iter->first+
"'}{'name'} = '"+ dat.fileName +
"';";
1781 ret +=
"\n$_FILES{'"+iter->first+
"'}{'type'} = '"+ dat.type +
"';";
1782 ret +=
"\n$_FILES{'"+iter->first+
"'}{'size'} = "+ CastUtil::lexical_cast<
string>(dat.length) +
";";
1783 ret +=
"\n$_FILES{'"+iter->first+
"'}{'tmp_name'} = '"+ dat.tmpFileName +
"';";
1784 ret +=
"\n$_FILES{'"+iter->first+
"'}{'error'} = 0;";
1792 string HttpRequest::toRubyVariablesString()
1795 ret +=
"SERVER = {}";
1796 ret +=
"\nSERVER_EX = {}";
1797 ret +=
"\nGET = {}";
1798 ret +=
"\nPOST = {}";
1799 ret +=
"\nFILES = {}";
1800 ret +=
"\nSERVER['HTTP_HOST'] = '"+this->getHost();
1801 ret +=
"'\nSERVER['HTTP_ACCEPT'] = '"+this->getAccept();
1802 ret +=
"'\nSERVER['HTTP_ACCEPT_CHARSET'] = '"+this->getAccept_chars();
1803 ret +=
"'\nSERVER['HTTP_ACCEPT_ENCODING'] = '"+this->getAccept_encod();
1804 ret +=
"'\nSERVER['HTTP_ACCEPT_LANGUAGE'] = '"+this->getAccept_lang();
1805 ret +=
"'\nSERVER_EX['CACHE_CNTRL'] = '"+this->getCache_ctrl();
1806 ret +=
"'\nSERVER['HTTP_CONNECTION'] = '"+this->getConnection();
1807 ret +=
"'\nSERVER_EX['HTTP_CONTENT'] = '"+this->getContent();
1808 ret +=
"'\nSERVER_EX['HTTP_CNTENT_LENGTH'] = '"+this->getContent_len();
1809 ret +=
"'\nSERVER_EX['HTTP_CNTENT_TYPE'] = '"+this->getContent_type();
1810 ret +=
"'\nSERVER_EX['HTTP_VERSION'] = '"+this->getHttpVersion();
1811 ret +=
"'\nSERVER['REQUEST_METHOD'] = '"+this->getMethod();
1812 ret +=
"'\nSERVER['HTTP_USER_AGENT'] = '"+this->getUser_agent();
1813 ret +=
"'\nSERVER['REQUEST_URI'] = '"+this->getUrl();
1814 ret +=
"'\nSERVER_EX['HTTP_REQ_FILE'] = '"+this->getFile();
1815 ret +=
"'\nSERVER_EX['CONTEXT_NAME'] = '"+this->getCntxt_name();
1816 ret +=
"'\nSERVER['DOCUMENT_ROOT'] = '"+this->getCntxt_root();
1817 ret +=
"'\nSERVER_EX['DEFAULT_LOCALE'] = '"+this->getDefaultLocale();
1818 ret +=
"'\nSERVER['HTTP_HOST'] = '"+this->getContent_boundary() +
"'\n";
1819 if(this->queryParams.size()>0)
1821 RMap::iterator iter;
1822 for (iter=this->queryParams.begin();iter!=this->queryParams.end();iter++)
1824 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1826 string key = iter->first.substr(0, iter->first.find(
"["));
1827 ret +=
"\nif(!GET.has_key?('"+key+
"'))\nGET['"+key+
"']={}\nend";
1828 ret += (
"\nGET['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1829 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"'");
1832 ret +=
"\nGET['"+iter->first+
"'] = '"+ iter->second +
"'";
1835 if(this->requestParams.size()>0)
1837 RMap::iterator iter;
1838 for (iter=this->requestParams.begin();iter!=this->requestParams.end();iter++)
1840 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1842 string key = iter->first.substr(0, iter->first.find(
"["));
1843 ret +=
"\nif(!POST.has_key?('"+key+
"'))\nPOST['"+key+
"']={}\nend";
1844 ret += (
"\nPOST['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1845 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"'");
1848 ret +=
"\nPOST['"+iter->first+
"'] = '"+iter->second +
"'";
1851 if(this->requestParamsF.size()>0)
1853 FMap::iterator iter;
1854 for (iter=this->requestParamsF.begin();iter!=this->requestParamsF.end();iter++)
1857 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1859 string key = iter->first.substr(iter->first.find(
"["));
1860 StringUtil::replaceFirst(key,
"[",
"");
1861 StringUtil::replaceFirst(key,
"]",
"");
1862 ret +=
"\nif(!FILES.has_key?('"+iter->first.substr(0, iter->first.find(
"["))
1863 +
"'))\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']={}\nend";
1864 ret +=
"\nif(!FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"'].has_key?('"+key+
"'))"
1865 +
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']['"+key+
"']={}\nend";
1866 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1867 iter->first.substr(iter->first.find(
"[")) +
"['name'] = '"+ dat.fileName +
"'";
1868 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1869 iter->first.substr(iter->first.find(
"[")) +
"['type'] = '"+ dat.type +
"'";
1870 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1871 iter->first.substr(iter->first.find(
"[")) +
"['size'] = "+ CastUtil::lexical_cast<string>(dat.length);
1872 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1873 iter->first.substr(iter->first.find(
"[")) +
"['tmp_name'] = '"+ dat.tmpFileName +
"'";
1874 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1875 iter->first.substr(iter->first.find(
"[")) +
"['error'] = 0;";
1879 ret +=
"\nFILES['"+iter->first+
"'] = {}";
1880 ret +=
"\nFILES['"+iter->first+
"']['name'] = '"+ dat.fileName +
"'";
1881 ret +=
"\nFILES['"+iter->first+
"']['type'] = '"+ dat.type +
"'";
1882 ret +=
"\nFILES['"+iter->first+
"']['size'] = "+ CastUtil::lexical_cast<
string>(dat.length);
1883 ret +=
"\nFILES['"+iter->first+
"']['tmp_name'] = '"+ dat.tmpFileName +
"'";
1884 ret +=
"\nFILES['"+iter->first+
"']['error'] = 0";
1888 ret +=
"\nrequire ('"+this->getUrl()+
"')\n";
1892 string HttpRequest::toPythonVariablesString()
1895 ret +=
"SERVER = {}";
1896 ret +=
"\nSERVER_EX = {}";
1897 ret +=
"\nGET = {}";
1898 ret +=
"\nPOST = {}";
1899 ret +=
"\nFILES = {}";
1900 ret +=
"\nSERVER['HTTP_HOST'] = '"+this->getHost();
1901 ret +=
"'\nSERVER['HTTP_ACCEPT'] = '"+this->getAccept();
1902 ret +=
"'\nSERVER['HTTP_ACCEPT_CHARSET'] = '"+this->getAccept_chars();
1903 ret +=
"'\nSERVER['HTTP_ACCEPT_ENCODING'] = '"+this->getAccept_encod();
1904 ret +=
"'\nSERVER['HTTP_ACCEPT_LANGUAGE'] = '"+this->getAccept_lang();
1905 ret +=
"'\nSERVER_EX['CACHE_CNTRL'] = '"+this->getCache_ctrl();
1906 ret +=
"'\nSERVER['HTTP_CONNECTION'] = '"+this->getConnection();
1907 ret +=
"'\nSERVER_EX['HTTP_CONTENT'] = '"+this->getContent();
1908 ret +=
"'\nSERVER_EX['HTTP_CNTENT_LENGTH'] = '"+this->getContent_len();
1909 ret +=
"'\nSERVER_EX['HTTP_CNTENT_TYPE'] = '"+this->getContent_type();
1910 ret +=
"'\nSERVER_EX['HTTP_VERSION'] = '"+this->getHttpVersion();
1911 ret +=
"'\nSERVER['REQUEST_METHOD'] = '"+this->getMethod();
1912 ret +=
"'\nSERVER['HTTP_USER_AGENT'] = '"+this->getUser_agent();
1913 ret +=
"'\nSERVER['REQUEST_URI'] = '"+this->getUrl();
1914 ret +=
"'\nSERVER_EX['HTTP_REQ_FILE'] = '"+this->getFile();
1915 ret +=
"'\nSERVER_EX['CONTEXT_NAME'] = '"+this->getCntxt_name();
1916 ret +=
"'\nSERVER['DOCUMENT_ROOT'] = '"+this->getCntxt_root();
1917 ret +=
"'\nSERVER_EX['DEFAULT_LOCALE'] = '"+this->getDefaultLocale();
1918 ret +=
"'\nSERVER['HTTP_HOST'] = '"+this->getContent_boundary() +
"'\n";
1919 if(this->queryParams.size()>0)
1921 RMap::iterator iter;
1922 for (iter=this->queryParams.begin();iter!=this->queryParams.end();iter++)
1924 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1926 string key = iter->first.substr(0, iter->first.find(
"["));
1927 ret +=
"\nif '"+key+
"' not in GET:\n\tGET['"+key+
"']={}\n";
1928 ret += (
"\nGET['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1929 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"'");
1932 ret +=
"\nGET['"+iter->first+
"'] = '"+ iter->second +
"'";
1935 if(this->requestParams.size()>0)
1937 RMap::iterator iter;
1938 for (iter=this->requestParams.begin();iter!=this->requestParams.end();iter++)
1940 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1942 string key = iter->first.substr(0, iter->first.find(
"["));
1943 ret +=
"\nif '"+key+
"' not in POST:\n\tPOST['"+key+
"']={}\n";
1944 ret += (
"\nPOST['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1945 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"'");
1948 ret +=
"\nPOST['"+iter->first+
"'] = '"+iter->second +
"'";
1951 if(this->requestParamsF.size()>0)
1953 FMap::iterator iter;
1954 for (iter=this->requestParamsF.begin();iter!=this->requestParamsF.end();iter++)
1957 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
1959 string key = iter->first.substr(iter->first.find(
"["));
1960 StringUtil::replaceFirst(key,
"[",
"");
1961 StringUtil::replaceFirst(key,
"]",
"");
1962 ret +=
"\nif '"+iter->first.substr(0, iter->first.find(
"["))
1963 +
"' not in FILES:\n\tFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']={}\n";
1964 ret +=
"\nif '"+key+
"' not in FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']:\n"
1965 +
"\n\tFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']['"+key+
"']={}\n";
1966 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1967 iter->first.substr(iter->first.find(
"[")) +
"['name'] = '"+ dat.fileName +
"'";
1968 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1969 iter->first.substr(iter->first.find(
"[")) +
"['type'] = '"+ dat.type +
"'";
1970 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1971 iter->first.substr(iter->first.find(
"[")) +
"['size'] = "+ CastUtil::lexical_cast<string>(dat.length);
1972 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1973 iter->first.substr(iter->first.find(
"[")) +
"['tmp_name'] = '"+ dat.tmpFileName +
"'";
1974 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
1975 iter->first.substr(iter->first.find(
"[")) +
"['error'] = 0;";
1979 ret +=
"\nFILES['"+iter->first+
"'] = {}";
1980 ret +=
"\nFILES['"+iter->first+
"']['name'] = '"+ dat.fileName +
"'";
1981 ret +=
"\nFILES['"+iter->first+
"']['type'] = '"+ dat.type +
"'";
1982 ret +=
"\nFILES['"+iter->first+
"']['size'] = "+ CastUtil::lexical_cast<
string>(dat.length);
1983 ret +=
"\nFILES['"+iter->first+
"']['tmp_name'] = '"+ dat.tmpFileName +
"'";
1984 ret +=
"\nFILES['"+iter->first+
"']['error'] = 0";
1992 string HttpRequest::toLuaVariablesString()
1995 ret +=
"SERVER = {}";
1996 ret +=
"\nSERVER_EX = {}";
1997 ret +=
"\nGET = {}";
1998 ret +=
"\nPOST = {}";
1999 ret +=
"\nFILES = {}";
2000 ret +=
"\nSERVER['HTTP_HOST'] = '"+this->getHost();
2001 ret +=
"'\nSERVER['HTTP_ACCEPT'] = '"+this->getAccept();
2002 ret +=
"'\nSERVER['HTTP_ACCEPT_CHARSET'] = '"+this->getAccept_chars();
2003 ret +=
"'\nSERVER['HTTP_ACCEPT_ENCODING'] = '"+this->getAccept_encod();
2004 ret +=
"'\nSERVER['HTTP_ACCEPT_LANGUAGE'] = '"+this->getAccept_lang();
2005 ret +=
"'\nSERVER_EX['CACHE_CNTRL'] = '"+this->getCache_ctrl();
2006 ret +=
"'\nSERVER['HTTP_CONNECTION'] = '"+this->getConnection();
2007 ret +=
"'\nSERVER_EX['HTTP_CONTENT'] = '"+this->getContent();
2008 ret +=
"'\nSERVER_EX['HTTP_CNTENT_LENGTH'] = '"+this->getContent_len();
2009 ret +=
"'\nSERVER_EX['HTTP_CNTENT_TYPE'] = '"+this->getContent_type();
2010 ret +=
"'\nSERVER_EX['HTTP_VERSION'] = '"+this->getHttpVersion();
2011 ret +=
"'\nSERVER['REQUEST_METHOD'] = '"+this->getMethod();
2012 ret +=
"'\nSERVER['HTTP_USER_AGENT'] = '"+this->getUser_agent();
2013 ret +=
"'\nSERVER['REQUEST_URI'] = '"+this->getUrl();
2014 ret +=
"'\nSERVER_EX['HTTP_REQ_FILE'] = '"+this->getFile();
2015 ret +=
"'\nSERVER_EX['CONTEXT_NAME'] = '"+this->getCntxt_name();
2016 ret +=
"'\nSERVER['DOCUMENT_ROOT'] = '"+this->getCntxt_root();
2017 ret +=
"'\nSERVER_EX['DEFAULT_LOCALE'] = '"+this->getDefaultLocale();
2018 ret +=
"'\nSERVER['HTTP_HOST'] = '"+this->getContent_boundary() +
"'\n";
2019 if(this->queryParams.size()>0)
2021 RMap::iterator iter;
2022 for (iter=this->queryParams.begin();iter!=this->queryParams.end();iter++)
2024 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
2026 string key = iter->first.substr(0, iter->first.find(
"["));
2027 ret +=
"\nif GET['"+key+
"'] == nil then\nGET['"+key+
"']={}\nend\n";
2028 ret += (
"\nGET['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2029 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"'");
2032 ret +=
"\nGET['"+iter->first+
"'] = '"+ iter->second +
"'";
2035 if(this->requestParams.size()>0)
2037 RMap::iterator iter;
2038 for (iter=this->requestParams.begin();iter!=this->requestParams.end();iter++)
2040 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
2042 string key = iter->first.substr(0, iter->first.find(
"["));
2043 ret +=
"\nif POST['"+key+
"'] == nil then\nPOST['"+key+
"']={}\nend\n";
2044 ret += (
"\nPOST['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2045 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"'");
2048 ret +=
"\nPOST['"+iter->first+
"'] = '"+iter->second +
"'";
2051 if(this->requestParamsF.size()>0)
2053 FMap::iterator iter;
2054 for (iter=this->requestParamsF.begin();iter!=this->requestParamsF.end();iter++)
2057 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
2059 string key = iter->first.substr(iter->first.find(
"["));
2060 StringUtil::replaceFirst(key,
"[",
"");
2061 StringUtil::replaceFirst(key,
"]",
"");
2062 ret +=
"\nif FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"'] == nil then"
2063 +
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']={}\nend\n";
2064 ret +=
"\nif FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']['"+key+
"'] == nil then"
2065 +
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']['"+key+
"']={}\nend\n";
2066 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2067 iter->first.substr(iter->first.find(
"[")) +
"['name'] = '"+ dat.fileName +
"'";
2068 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2069 iter->first.substr(iter->first.find(
"[")) +
"['type'] = '"+ dat.type +
"'";
2070 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2071 iter->first.substr(iter->first.find(
"[")) +
"['size'] = "+ CastUtil::lexical_cast<string>(dat.length);
2072 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2073 iter->first.substr(iter->first.find(
"[")) +
"['tmp_name'] = '"+ dat.tmpFileName +
"'";
2074 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2075 iter->first.substr(iter->first.find(
"[")) +
"['error'] = 0;";
2079 ret +=
"\nFILES['"+iter->first+
"'] = {}";
2080 ret +=
"\nFILES['"+iter->first+
"']['name'] = '"+ dat.fileName +
"'";
2081 ret +=
"\nFILES['"+iter->first+
"']['type'] = '"+ dat.type +
"'";
2082 ret +=
"\nFILES['"+iter->first+
"']['size'] = "+ CastUtil::lexical_cast<
string>(dat.length);
2083 ret +=
"\nFILES['"+iter->first+
"']['tmp_name'] = '"+ dat.tmpFileName +
"'";
2084 ret +=
"\nFILES['"+iter->first+
"']['error'] = 0";
2088 ret +=
"\ndofile(\""+this->getUrl()+
"\")\n";
2092 string HttpRequest::toNodejsVariablesString()
2095 ret +=
"SERVER = {};";
2096 ret +=
"\nSERVER_EX = {};";
2097 ret +=
"\nGET = {};";
2098 ret +=
"\nPOST = {};";
2099 ret +=
"\nFILES = {};";
2100 ret +=
"\nSERVER['HTTP_HOST'] = '"+this->getHost();
2101 ret +=
"';\nSERVER['HTTP_ACCEPT'] = '"+this->getAccept();
2102 ret +=
"';\nSERVER['HTTP_ACCEPT_CHARSET'] = '"+this->getAccept_chars();
2103 ret +=
"';\nSERVER['HTTP_ACCEPT_ENCODING'] = '"+this->getAccept_encod();
2104 ret +=
"';\nSERVER['HTTP_ACCEPT_LANGUAGE'] = '"+this->getAccept_lang();
2105 ret +=
"';\nSERVER_EX['CACHE_CNTRL'] = '"+this->getCache_ctrl();
2106 ret +=
"';\nSERVER['HTTP_CONNECTION'] = '"+this->getConnection();
2107 ret +=
"';\nSERVER_EX['HTTP_CONTENT'] = '"+this->getContent();
2108 ret +=
"';\nSERVER_EX['HTTP_CNTENT_LENGTH'] = '"+this->getContent_len();
2109 ret +=
"';\nSERVER_EX['HTTP_CNTENT_TYPE'] = '"+this->getContent_type();
2110 ret +=
"';\nSERVER_EX['HTTP_VERSION'] = '"+this->getHttpVersion();
2111 ret +=
"';\nSERVER['REQUEST_METHOD'] = '"+this->getMethod();
2112 ret +=
"';\nSERVER['HTTP_USER_AGENT'] = '"+this->getUser_agent();
2113 ret +=
"';\nSERVER['REQUEST_URI'] = '"+this->getUrl();
2114 ret +=
"';\nSERVER_EX['HTTP_REQ_FILE'] = '"+this->getFile();
2115 ret +=
"';\nSERVER_EX['CONTEXT_NAME'] = '"+this->getCntxt_name();
2116 ret +=
"';\nSERVER['DOCUMENT_ROOT'] = '"+this->getCntxt_root();
2117 ret +=
"';\nSERVER_EX['DEFAULT_LOCALE'] = '"+this->getDefaultLocale();
2118 ret +=
"';\nSERVER['HTTP_HOST'] = '"+this->getContent_boundary() +
"';\n";
2119 if(this->queryParams.size()>0)
2121 RMap::iterator iter;
2122 for (iter=this->queryParams.begin();iter!=this->queryParams.end();iter++)
2124 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
2126 ret +=
"\nif((GET['"+iter->first.substr(0, iter->first.find(
"["))+
"'])==undefined)\n{\nGET['"+iter->first.substr(0, iter->first.find(
"["))+
"']={};\n}\n";
2127 ret += (
"\nGET['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2128 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"';");
2131 ret +=
"\nGET['"+iter->first+
"'] = '"+ iter->second +
"';";
2134 if(this->requestParams.size()>0)
2136 RMap::iterator iter;
2137 for (iter=this->requestParams.begin();iter!=this->requestParams.end();iter++)
2139 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
2141 ret +=
"\nif((POST['"+iter->first.substr(0, iter->first.find(
"["))+
"'])==undefined)\n{\nPOST['"+iter->first.substr(0, iter->first.find(
"["))+
"']={};\n}\n";
2142 ret += (
"\nPOST['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2143 iter->first.substr(iter->first.find(
"[")) +
" = '"+iter->second +
"';");
2146 ret +=
"\nPOST['"+iter->first+
"'] = '"+iter->second +
"';";
2149 if(this->requestParamsF.size()>0)
2151 FMap::iterator iter;
2152 for (iter=this->requestParamsF.begin();iter!=this->requestParamsF.end();iter++)
2155 if(iter->first.find(
"[")!=string::npos && iter->first.find(
"]")!=string::npos)
2157 ret +=
"\nif((FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"'])==undefined)\n{\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']={};\n}\n";
2158 ret +=
"\nif((FILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']"+iter->first.substr(iter->first.find(
"["))+
")==undefined)\n"
2159 +
"{\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']"+iter->first.substr(iter->first.find(
"["))+
"={};\n}\n";
2160 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2161 iter->first.substr(iter->first.find(
"[")) +
"['name'] = '"+ dat.fileName +
"';";
2162 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2163 iter->first.substr(iter->first.find(
"[")) +
"['type'] = '"+ dat.type +
"';";
2164 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2165 iter->first.substr(iter->first.find(
"[")) +
"['size'] = "+ CastUtil::lexical_cast<string>(dat.length) +
";";
2166 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2167 iter->first.substr(iter->first.find(
"[")) +
"['tmp_name'] = '"+ dat.tmpFileName +
"';";
2168 ret +=
"\nFILES['"+iter->first.substr(0, iter->first.find(
"["))+
"']" +
2169 iter->first.substr(iter->first.find(
"[")) +
"['error'] = 0;";
2173 ret +=
"\nif(!isset(FILES['"+iter->first+
"']))\n{\nFILES['"+iter->first+
"']={};\n}\n";
2174 ret +=
"\nFILES['"+iter->first+
"']['name'] = '"+ dat.fileName +
"';";
2175 ret +=
"\nFILES['"+iter->first+
"']['type'] = '"+ dat.type +
"';";
2176 ret +=
"\nFILES['"+iter->first+
"']['size'] = "+ CastUtil::lexical_cast<
string>(dat.length) +
";";
2177 ret +=
"\nFILES['"+iter->first+
"']['tmp_name'] = '"+ dat.tmpFileName +
"';";
2178 ret +=
"\nFILES['"+iter->first+
"']['error'] = 0;";
2182 ret +=
"\nrequire('"+this->getUrl()+
"');";
2186 RMap HttpRequest::getAllParams()
2188 map<string,string>::iterator it;
2189 map<string,string> reqparams = this->getRequestParams();
2190 map<string,string> qryparams = this->getQueryParams();
2191 for(it=qryparams.begin();it!=qryparams.end();it++)
2193 reqparams[it->first] = it->second;