64 case 200:
return "OK";
65 case 201:
return "Created";
66 case 202:
return "Accepted";
67 case 204:
return "No Content";
68 case 300:
return "Multiple Choices";
69 case 301:
return "Moved Permanently";
70 case 302:
return "Moved Temporarily";
71 case 304:
return "Not Modified";
72 case 400:
return "Bad Request";
73 case 401:
return "Unauthorized";
74 case 403:
return "Forbidden";
75 case 404:
return "Not Found";
76 case 500:
return "Internal Server Error";
77 case 501:
return "Not Implemented";
78 case 502:
return "Bad Gateway";
79 case 503:
return "Service Unavailable";
115 bool IsCr(
const char& Ch){
return Ch==13;}
116 bool IsLf(
const char& Ch){
return Ch==10;}
117 bool IsSp(
const char& Ch){
return Ch==32;}
118 bool IsHt(
const char& Ch){
return Ch==9;}
129 for (
int ChN=0; ChN<Str.
Len(); ChN++){
SetChTy(ChTy, Str[ChN]);}}
135 ChTyV(
TCh::Vals), LcChV(
TCh::Vals){
158 for (
int ChN=0; ChN<Str.
Len(); ChN++){LcStr+=
GetLcCh(Str[ChN]);}
190 SIn(_SIn), EofChPrS(), Ch(
' '), AtEof(false), SfMem(50000){
223 int GetInt(
const int& RqPlaces=-1);
233 AtEof=
true;
return 0;
240 if (EofChPrS.
Empty()){
256 if (!SIn->
Eof()){SfMem+=
Ch;}
266 if (MethodNm==THttp::GetMethodNm){Method=
hrmGet;}
267 else if (MethodNm==THttp::HeadMethodNm){Method=
hrmHead;}
268 else if (MethodNm==THttp::PostMethodNm){Method=
hrmPost;}
275 while ((!
Eof())&&(!ChDef.
IsSp(Ch))){
279 static TStr LocalBaseUrlStr=
"http://localhost/";
288 while ((!
Eof())&&(!ChDef.
IsSp(Ch))){
296 static const TChA MouldChA=
"http/N.N NNN ";
297 TChA TestChA(MouldChA);
298 int TestLen=TestChA.
Len();
299 if (1+
Len()<TestLen){
return false;}
301 {
for (
int ChN=1; ChN<TestLen; ChN++){
303 {
for (
int ChN=1; ChN<TestLen; ChN++){
304 PutCh(TestChA[TestLen-ChN-1]);}}
305 {
for (
int ChN=0; ChN<MouldChA.
Len(); ChN++){
306 if (MouldChA[ChN]==
'N'){
307 if (!ChDef.
IsDigit(TestChA[ChN])){
return false;}
309 if (MouldChA[ChN]!=TestChA[ChN]){
return false;}
406 if (!ExpectStr.
Empty()){
417 if (!ExpectStr.
Empty()){
425 int Int=0;
int CurPlaces=0;
426 do {Int=Int*10+Ch-
'0'; CurPlaces++;
GetCh();
427 }
while ((CurPlaces<RqPlaces)&&(ChDef.
IsDigit(Ch)));
439 if (
IsLws()){FldValStr+=
' ';}
452 SIn(_SIn), Chs(SIn->Len()), ChN(0), HttpExCd(_HttpExCd){}
456 if (ChN>=Chs){
throw THttpEx(HttpExCd);}
457 ChN++;
return SIn->
GetCh();}
467 if (ChRet.
Eof()){
return;}
469 if (ChRet.
GetCh()!=
'?'){
473 while (!ChRet.
Eof()){
474 char Ch; KeyNm.
Clr(); ValStr.
Clr();
476 while ((Ch=ChRet.
GetCh())!=
'='){
479 char Ch1=ChRet.
GetCh();
481 char Ch2=ChRet.
GetCh();
484 case '+': KeyNm.
AddCh(
' ');
break;
486 default: KeyNm.
AddCh(Ch);
493 while ((!ChRet.
Eof())&&((Ch=ChRet.
GetCh())!=
'&')){
496 char Ch1=ChRet.
GetCh();
498 char Ch2=ChRet.
GetCh();
501 case '+': ValStr.
AddCh(
' ');
break;
503 default: ValStr.
AddCh(Ch);
536 if (!Lx.
IsCrLf()){
return;}
560 const TStr LocalBaseUrlStr=
"http://localhost/";
571 (!
IsFldNm(THttp::ContTypeFldNm))||
572 (
GetFldVal(THttp::ContTypeFldNm)==THttp::TextHtmlFldVal)||
573 (
GetFldVal(THttp::ContTypeFldNm)==THttp::AppW3FormFldVal))){
582 Ok(false), MajorVerN(0), MinorVerN(0), Method(
hrmUndef),
583 FldNmToValH(), UrlEnv(
TUrlEnv::New()),
593 const TStr& ContTypeFldVal,
const TMem& _BodyMem,
const int& FetchId):
595 MajorVerN(1), MinorVerN(0),
600 HdStr(), BodyMem(_BodyMem){
605 HdChA+=
GetMethodNm(); HdChA+=
' '; HdChA+=AbsPath; HdChA+=
" HTTP/1.0\r\n";
608 if (!ContTypeFldVal.
Empty()){
611 HdChA+=ContTypeFldVal; HdChA+=
"\r\n";
618 HdChA+=HostNm; HdChA+=
"\r\n";
622 if (
Url->
IsOk()&&(FetchId!=-1)){
626 HdChA+=FetchIdStr; HdChA+=
"\r\n";
696 HdChA+=FldNm; HdChA+=
": "; HdChA+=FldVal; HdChA+=
"\r\n";
741 const bool& CacheCtrlP,
const PSIn& BodySIn,
const TStr LocStr):
742 Ok(true), MajorVerN(1), MinorVerN(0), StatusCd(_StatusCd), ReasonPhrase(),
743 FldNmToValVH(20), HdStr(), BodyMem(){
755 if (!LocStr.
Empty()){
756 AddHdFld(
"Location", LocStr, HdChA);}
757 if (!BodySIn.
Empty()){
759 AddHdFld(THttp::ContTypeFldNm, ContTypeVal, HdChA);
761 AddHdFld(THttp::AcceptRangesFldNm,
"bytes", HdChA);
764 AddHdFld(THttp::ContLenFldNm, ContLenVal, HdChA);
767 AddHdFld(THttp::CacheCtrlFldNm,
"no-cache", HdChA);}
773 if (!BodySIn.
Empty()){
778 Ok(false), MajorVerN(0), MinorVerN(0), StatusCd(-1), ReasonPhrase(),
779 FldNmToValVH(20), HdStr(), BodyMem(){
794 if (ValV.
Len()>0){
return ValV[ValN];}
else {
return TStr();}
819 HdChA+=NrFldNm; HdChA+=
": "; HdChA+=FldVal;
826 CookieKeyValDmPathQuV.
Clr();
828 for (
int CookieN=0; CookieN<CookieFldValV.
Len(); CookieN++){
829 TStr CookieFldVal=CookieFldValV[CookieN];
833 for (
int KeyValStrN=0; KeyValStrN<KeyValStrV.
Len(); KeyValStrN++){
834 TStr KeyValStr=KeyValStrV[KeyValStrN];
836 if (KeyValStr.
IsChIn(
'=')){
837 KeyValStrV[KeyValStrN].SplitOnCh(KeyNm,
'=', ValStr);
842 if (KeyNm==
"expires"){}
843 else if (KeyNm==
"domain"){DmNm=ValStr;}
844 else if (KeyNm==
"path"){PathStr=ValStr;}
845 else if (KeyNm==
"expires"){}
846 else if (KeyNm==
"secure"){}
847 else if (KeyNm==
"httponly"){}
848 else if (!KeyNm.
Empty()){
852 for (
int KeyValPrN=0; KeyValPrN<KeyValPrV.
Len(); KeyValPrN++){
853 TStr KeyNm=KeyValPrV[KeyValPrN].Val1;
854 TStr ValStr=KeyValPrV[KeyValPrN].Val2;
855 CookieKeyValDmPathQuV.
Add(
TStrQu(KeyNm, ValStr, DmNm, PathStr));
863 return MOut.GetSIn();
TQuad< TStr, TStr, TStr, TStr > TStrQu
static bool IsHex(const char &Ch)
void ParseSearch(const TStr &SearchStr)
bool IsLws(const char &Ch)
TStr GetFldVal(const TStr &FldNm) const
virtual int Len() const =0
static const TStr ContTypeFldNm
static const TStr ImageIcoFldVal
TStr GetAsStr(const char &NewNullCh='\0') const
const TStrStrH & GetFldValH() const
THttpEx(const THttpExCd &_HttpExCd)
void AddFldVal(const TStr &FldNm, const TStr &FldVal)
TPair< TStr, TStr > TStrPr
static const int BadRqStatusCd
static TStr GetNrStr(const TStr &Str)
void GetFldValV(const TStr &FldNm, TStrV &FldValV) const
static const TStr GetMethodNm
TStr GetFldVal(const TStr &FldNm, const int &ValN=0) const
static const TStr GifFExt
static const TStr HttpStr
static const TStr HostFldNm
static const int RedirStatusCd
void PutCh(const int &ChN, const char &Ch)
void AddToKeyVal(const TStr &KeyNm, const TStr &ValStr)
void AddCh(const char &Ch, const int &MxLen=-1)
TSizeTy Len() const
Returns the number of elements in the vector.
TStr GetSpec(const TStr &ExpectStr=TStr())
bool IsDigit(const char &Ch)
TStr GetRespReasonPhrase()
bool IsFldNm(const TStr &FldNm) const
static int GetHex(const char &Ch)
static const TStr HtmlFExt
static PUrl New(const TStr &RelUrlStr, const TStr &BaseUrlStr=TStr())
static const TStr AcceptRangesFldNm
bool IsOk(const TUrlScheme _Scheme=usUndef) const
bool IsText(const char &Ch)
bool IsLf(const char &Ch)
static const TStr ConnFldNm
const TDat & GetDat(const TKey &Key) const
THttpRqMethod GetRqMethod()
static const TStr TextCssFldVal
static TStr GetReasonPhrase(const int &StatusCd)
void ParseHttpResp(const PSIn &SIn)
static const TStr AcceptFldNm
static const int ErrStatusCd
static bool IsHtmlFExt(const TStr &FExt)
static bool IsGifFExt(const TStr &FExt)
static const TStr TextPlainFldVal
bool IsDQuote(const char &Ch)
THttpChRet(const PSIn &_SIn, const THttpExCd &_HttpExCd)
static const TStr CookieFldNm
static const TStr HeadMethodNm
static const TStr PostMethodNm
static const TStr ColonStr
TStr GetToken(const TStr &ExpectStr=TStr())
static const TStr ImageGifFldVal
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
THttpResp(const int &_StatusCd, const TStr &ContTypeVal, const bool &CacheCtrlP, const PSIn &BodySIn, const TStr LocStr)
static const TStr AppOctetFldVal
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
static const TStr HtmFExt
static const int ErrNotFoundStatusCd
static const TStr UndefMethodNm
TPair< TBool, TCh > TBoolChPr
bool IsSuffix(const char *Str) const
static const TStr CacheCtrlFldNm
static PSIn New(const TStr &Str)
static const TStr LocFldNm
void GetCookieKeyValDmPathQuV(TStrQuV &CookieKeyValDmPathQuV)
void AddFldVal(const TStr &FldNm, const TStr &FldVal)
THttpLx & operator=(const THttpLx &)
bool IsSp(const char &Ch)
TStr GetLcStr(const TStr &Str)
static const TStr TextHtmlFldVal
bool IsFldVal(const TStr &FldNm, const TStr &FldVal) const
void Trunc(const int &_BfL)
static const TStr AppJSonFldVal
static const int OkStatusCd
static const TStr ContLenFldNm
static const TStr SlashStr
static const TStr TextJavaScriptFldVal
static const TStr TextWmlFldVal
bool IsAlpha(const char &Ch)
static void LoadMem(const PSIn &SIn, TMem &Mem)
static const TStr TextXmlFldVal
TStr GetSearchStr() const
bool IsCr(const char &Ch)
static const TStr ConnKeepAliveFldVal
char GetLcCh(const char &Ch)
THttpChDef & operator=(const THttpChDef &)
bool IsFldNm(const TStr &FldNm) const
void ParseHttpRq(const PSIn &SIn)
bool IsCtl(const char &Ch)
bool IsChIn(const char &Ch) const
void AddHdFld(const TStr &FldNm, const TStr &FldVal, TChA &HdChA)
int PutStr(const char *CStr)
void SplitOnAllCh(const char &SplitCh, TStrV &StrV, const bool &SkipEmpty=true) const
static const int InternalErrStatusCd
void SetLcCh(const TStr &Str)
static const TStr TextFldVal
static const TStr FetchIdFldNm
static const TStr AppW3FormFldVal
int GetChTy(const char &Ch)
THttpChRet & operator=(const THttpChRet &)
static const TStr ImagePngFldVal
void SetChTy(const THttpChTy &ChTy, const char &Ch)
bool IsKey(const TKey &Key) const
bool IsSpec(const char &Ch)
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
bool IsFldVal(const TStr &FldNm, const TStr &FldVal) const
static const TStr SrvFldNm
THttpLx(const PSIn &_SIn)
int GetInt(const int &RqPlaces=-1)
static const TStr ImageJpgFldVal
void PutCh(const char &_Ch)
TDat & AddDat(const TKey &Key)
bool IsHt(const char &Ch)
const TKey & GetKey(const int &KeyId) const
const TStr & GetMethodNm() const
static const TStr AppSoapXmlFldVal
void Clr(const bool &DoDel=true)
static const TStr SetCookieFldNm