SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
THttpRq Class Reference

#include <http.h>

Collaboration diagram for THttpRq:

Public Member Functions

 THttpRq (const PSIn &SIn)
 
 THttpRq (const THttpRqMethod &_Method, const PUrl &_Url, const TStr &ContTypeFldVal, const TMem &_BodyMem, const int &FetchId=-1)
 
 ~THttpRq ()
 
 THttpRq (TSIn &)
 
void Save (TSOut &)
 
THttpRqoperator= (const THttpRq &)
 
bool IsOk () const
 
bool IsComplete () const
 
THttpRqMethod GetMethod () const
 
const TStrGetMethodNm () const
 
PUrl GetUrl () const
 
PUrlEnv GetUrlEnv () const
 
bool IsFldNm (const TStr &FldNm) const
 
TStr GetFldVal (const TStr &FldNm) const
 
bool IsFldVal (const TStr &FldNm, const TStr &FldVal) const
 
void AddFldVal (const TStr &FldNm, const TStr &FldVal)
 
const TStrStrHGetFldValH () const
 
TStr GetHdStr () const
 
bool IsBody () const
 
int GetBodyLen () const
 
TStr GetBodyAsStr () const
 
PSIn GetBodyAsSIn () const
 
void GetBodyAsMem (TMem &Mem) const
 
void GetAsMem (TMem &Mem) const
 
bool IsContType (const TStr &ContTypeStr) const
 
bool IsContLen (int &ContLen) const
 
TStr GetStr () const
 

Static Public Member Functions

static PHttpRq New (const PSIn &SIn)
 
static PHttpRq New (const THttpRqMethod &Method, const PUrl &Url, const TStr &ContTypeFldVal, const TMem &BodyMem)
 
static PHttpRq New (const PUrl &Url, const int &FetchId=-1)
 
static PHttpRq Load (TSIn &)
 

Private Member Functions

void ParseSearch (const TStr &SearchStr)
 
void ParseHttpRq (const PSIn &SIn)
 

Private Attributes

TCRef CRef
 
bool Ok
 
bool CompleteP
 
int MajorVerN
 
int MinorVerN
 
THttpRqMethod Method
 
PUrl Url
 
TStrStrH FldNmToValH
 
PUrlEnv UrlEnv
 
TStr HdStr
 
TMem BodyMem
 

Friends

class TPt< THttpRq >
 

Detailed Description

Definition at line 67 of file http.h.

Constructor & Destructor Documentation

THttpRq::THttpRq ( const PSIn SIn)

Definition at line 581 of file http.cpp.

References Ok, and ParseHttpRq().

581  :
582  Ok(false), MajorVerN(0), MinorVerN(0), Method(hrmUndef),
584  HdStr(), BodyMem(){
585  try {
586  ParseHttpRq(SIn);
587  }
588  catch (const THttpEx&){Ok=false;}
589 }
TStrStrH FldNmToValH
Definition: http.h:74
bool Ok
Definition: http.h:69
TStr HdStr
Definition: http.h:76
static PUrlEnv New()
Definition: url.h:113
Definition: http.h:65
int MinorVerN
Definition: http.h:71
TMem BodyMem
Definition: http.h:77
void ParseHttpRq(const PSIn &SIn)
Definition: http.cpp:513
THttpRqMethod Method
Definition: http.h:72
int MajorVerN
Definition: http.h:71
PUrlEnv UrlEnv
Definition: http.h:75

Here is the call graph for this function:

THttpRq::THttpRq ( const THttpRqMethod _Method,
const PUrl _Url,
const TStr ContTypeFldVal,
const TMem _BodyMem,
const int &  FetchId = -1 
)

Definition at line 591 of file http.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), TStr::Empty(), FldNmToValH, TUrl::GetHostNm(), GetMethodNm(), THttpLx::GetNrStr(), TUrl::GetPathStr(), TUrl::GetSearchStr(), TInt::GetStr(), HdStr, TUrl::IsOk(), Ok, ParseSearch(), and Url.

593  :
594  Ok(false),
595  MajorVerN(1), MinorVerN(0),
596  Method(_Method),
597  Url(_Url),
598  FldNmToValH(),
599  UrlEnv(TUrlEnv::New()),
600  HdStr(), BodyMem(_BodyMem){
601  // compose head-http-request
602  TChA HdChA;
603  if (Url->IsOk()){
604  TStr AbsPath=Url->GetPathStr()+Url->GetSearchStr();
605  HdChA+=GetMethodNm(); HdChA+=' '; HdChA+=AbsPath; HdChA+=" HTTP/1.0\r\n";
606  }
607  // add content-type
608  if (!ContTypeFldVal.Empty()){
610  HdChA+=THttpLx::GetNrStr(THttp::ContTypeFldNm); HdChA+=": ";
611  HdChA+=ContTypeFldVal; HdChA+="\r\n";
612  }
613  // add host
614  if (Url->IsOk()){
615  TStr HostNm=Url->GetHostNm();
617  HdChA+=THttpLx::GetNrStr(THttp::HostFldNm); HdChA+=": ";
618  HdChA+=HostNm; HdChA+="\r\n";
620  }
621  // add fetch-id
622  if (Url->IsOk()&&(FetchId!=-1)){
623  TStr FetchIdStr=TInt::GetStr(FetchId);
625  HdChA+=THttpLx::GetNrStr(THttp::FetchIdFldNm); HdChA+=": ";
626  HdChA+=FetchIdStr; HdChA+="\r\n";
627  }
628  // finish head-http-request
629  if (Url->IsOk()){
630  HdChA+="\r\n";
631  HdStr=HdChA;
632  }
633  // set http-request ok
634  Ok=true;
635 }
void ParseSearch(const TStr &SearchStr)
Definition: http.cpp:462
TStrStrH FldNmToValH
Definition: http.h:74
static const TStr ContTypeFldNm
Definition: http.h:12
TStr GetStr() const
Definition: dt.h:1200
static TStr GetNrStr(const TStr &Str)
Definition: http.cpp:226
static const TStr HostFldNm
Definition: http.h:14
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
bool Ok
Definition: http.h:69
TStr GetPathStr() const
Definition: url.h:46
TStr GetHostNm() const
Definition: url.h:41
TStr HdStr
Definition: http.h:76
static PUrlEnv New()
Definition: url.h:113
PUrl Url
Definition: http.h:73
Definition: dt.h:201
TStr GetSearchStr() const
Definition: url.h:49
int MinorVerN
Definition: http.h:71
TMem BodyMem
Definition: http.h:77
Definition: dt.h:412
bool Empty() const
Definition: dt.h:491
THttpRqMethod Method
Definition: http.h:72
int MajorVerN
Definition: http.h:71
static const TStr FetchIdFldNm
Definition: http.h:20
PUrlEnv UrlEnv
Definition: http.h:75
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
const TStr & GetMethodNm() const
Definition: http.cpp:637

Here is the call graph for this function:

THttpRq::~THttpRq ( )
inline

Definition at line 93 of file http.h.

93 {}
THttpRq::THttpRq ( TSIn )
inline

Definition at line 94 of file http.h.

References Fail.

94 {Fail;}
#define Fail
Definition: bd.h:238

Member Function Documentation

void THttpRq::AddFldVal ( const TStr FldNm,
const TStr FldVal 
)

Definition at line 664 of file http.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), FldNmToValH, and THttpLx::GetNrStr().

664  {
665  TStr NrFldNm=THttpLx::GetNrStr(FldNm);
666  FldNmToValH.AddDat(NrFldNm, FldVal);
667 }
TStrStrH FldNmToValH
Definition: http.h:74
static TStr GetNrStr(const TStr &Str)
Definition: http.cpp:226
Definition: dt.h:412
TDat & AddDat(const TKey &Key)
Definition: hash.h:238

Here is the call graph for this function:

void THttpRq::GetAsMem ( TMem Mem) const
inline

Definition at line 120 of file http.h.

References TMem::Clr().

120 {Mem.Clr(); Mem+=HdStr; Mem+=BodyMem;}
TStr HdStr
Definition: http.h:76
TMem BodyMem
Definition: http.h:77
void Clr(const bool &DoDel=true)
Definition: dt.h:131

Here is the call graph for this function:

void THttpRq::GetBodyAsMem ( TMem Mem) const
inline

Definition at line 119 of file http.h.

References TMem::Clr().

119 {Mem.Clr(); Mem += BodyMem;}
TMem BodyMem
Definition: http.h:77
void Clr(const bool &DoDel=true)
Definition: dt.h:131

Here is the call graph for this function:

PSIn THttpRq::GetBodyAsSIn ( ) const
inline

Definition at line 118 of file http.h.

References TMemIn::New().

118 { return TMemIn::New(BodyMem); }
static PSIn New(const TMem &Mem)
Definition: dt.h:165
TMem BodyMem
Definition: http.h:77

Here is the call graph for this function:

TStr THttpRq::GetBodyAsStr ( ) const
inline

Definition at line 117 of file http.h.

117 { return BodyMem.GetAsStr(' ');}
TStr GetAsStr(const char &NewNullCh='\0') const
Definition: dt.cpp:303
TMem BodyMem
Definition: http.h:77
int THttpRq::GetBodyLen ( ) const
inline

Definition at line 116 of file http.h.

116 { return BodyMem.Len(); }
int Len() const
Definition: dt.h:134
TMem BodyMem
Definition: http.h:77
TStr THttpRq::GetFldVal ( const TStr FldNm) const

Definition at line 650 of file http.cpp.

References FldNmToValH, THash< TKey, TDat, THashFunc >::GetDat(), THttpLx::GetNrStr(), and THash< TKey, TDat, THashFunc >::IsKey().

Referenced by IsFldVal(), and ParseHttpRq().

650  {
651  TStr NrFldNm=THttpLx::GetNrStr(FldNm);
652  if (FldNmToValH.IsKey(NrFldNm)){
653  return FldNmToValH.GetDat(NrFldNm);
654  } else {
655  return TStr();
656  }
657 }
TStrStrH FldNmToValH
Definition: http.h:74
static TStr GetNrStr(const TStr &Str)
Definition: http.cpp:226
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
Definition: dt.h:412
bool IsKey(const TKey &Key) const
Definition: hash.h:258

Here is the call graph for this function:

Here is the caller graph for this function:

const TStrStrH & THttpRq::GetFldValH ( ) const

Definition at line 669 of file http.cpp.

References FldNmToValH.

669  {
670  return FldNmToValH;
671 }
TStrStrH FldNmToValH
Definition: http.h:74
TStr THttpRq::GetHdStr ( ) const
inline

Definition at line 114 of file http.h.

114 {return HdStr;}
TStr HdStr
Definition: http.h:76
THttpRqMethod THttpRq::GetMethod ( ) const
inline

Definition at line 103 of file http.h.

103 {return Method;}
THttpRqMethod Method
Definition: http.h:72
const TStr & THttpRq::GetMethodNm ( ) const

Definition at line 637 of file http.cpp.

References THttp::GetMethodNm, THttp::HeadMethodNm, hrmGet, hrmHead, hrmPost, Method, THttp::PostMethodNm, and THttp::UndefMethodNm.

Referenced by GetStr(), and THttpRq().

637  {
638  switch (Method){
639  case hrmGet: return THttp::GetMethodNm;
640  case hrmHead: return THttp::HeadMethodNm;
641  case hrmPost: return THttp::PostMethodNm;
642  default: return THttp::UndefMethodNm;
643  }
644 }
static const TStr GetMethodNm
Definition: http.h:56
Definition: http.h:65
Definition: http.h:65
static const TStr HeadMethodNm
Definition: http.h:57
static const TStr PostMethodNm
Definition: http.h:58
static const TStr UndefMethodNm
Definition: http.h:59
Definition: http.h:65
THttpRqMethod Method
Definition: http.h:72

Here is the caller graph for this function:

TStr THttpRq::GetStr ( ) const

Definition at line 673 of file http.cpp.

References BodyMem, THttp::ContLenFldNm, TMem::Empty(), FldNmToValH, TMem::GetAsStr(), THash< TKey, TDat, THashFunc >::GetKey(), GetMethodNm(), TInt::GetStr(), TUrl::GetUrlStr(), TMem::Len(), THash< TKey, TDat, THashFunc >::Len(), and Url.

673  {
674  TChA ChA;
675  ChA+=GetMethodNm(); ChA+=' ';
676  ChA+=Url->GetUrlStr(); ChA+=' ';
677  ChA+="HTTP/1.0\r\n";
678  for (int FldN=0; FldN<FldNmToValH.Len(); FldN++){
679  ChA+=FldNmToValH.GetKey(FldN); ChA+=": ";
680  ChA+=FldNmToValH[FldN]; ChA+="\r\n";
681  }
682  if (!BodyMem.Empty()) {
683  ChA+=THttp::ContLenFldNm; ChA+=": ";
684  ChA+=TInt::GetStr(BodyMem.Len()); ChA+="\r\n";
685  }
686  ChA+="\r\n";
687  ChA+=BodyMem.GetAsStr();
688  return ChA;
689 }
TStrStrH FldNmToValH
Definition: http.h:74
TStr GetStr() const
Definition: dt.h:1200
TStr GetAsStr(const char &NewNullCh='\0') const
Definition: dt.cpp:303
int Len() const
Definition: dt.h:134
TStr GetUrlStr() const
Definition: url.h:36
static const TStr ContLenFldNm
Definition: http.h:13
PUrl Url
Definition: http.h:73
Definition: dt.h:201
TMem BodyMem
Definition: http.h:77
bool Empty() const
Definition: dt.h:135
int Len() const
Definition: hash.h:228
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
const TStr & GetMethodNm() const
Definition: http.cpp:637

Here is the call graph for this function:

PUrl THttpRq::GetUrl ( ) const
inline

Definition at line 105 of file http.h.

105 {return Url;}
PUrl Url
Definition: http.h:73
PUrlEnv THttpRq::GetUrlEnv ( ) const
inline

Definition at line 106 of file http.h.

106 {return UrlEnv;}
PUrlEnv UrlEnv
Definition: http.h:75
bool THttpRq::IsBody ( ) const
inline

Definition at line 115 of file http.h.

115 { return !BodyMem.Empty(); }
TMem BodyMem
Definition: http.h:77
bool Empty() const
Definition: dt.h:135
bool THttpRq::IsComplete ( ) const
inline

Definition at line 102 of file http.h.

102 {return CompleteP;}
bool CompleteP
Definition: http.h:70
bool THttpRq::IsContLen ( int &  ContLen) const
inline

Definition at line 125 of file http.h.

References THttp::ContLenFldNm.

125  {
126  return GetFldVal(THttp::ContLenFldNm).IsInt(ContLen);}
TStr GetFldVal(const TStr &FldNm) const
Definition: http.cpp:650
bool IsInt(const bool &Check, const int &MnVal, const int &MxVal, int &Val) const
Definition: dt.cpp:1159
static const TStr ContLenFldNm
Definition: http.h:13
bool THttpRq::IsContType ( const TStr ContTypeStr) const
inline

Definition at line 123 of file http.h.

References THttp::ContTypeFldNm.

123  {
124  return GetFldVal(THttp::ContTypeFldNm).IsStrIn(ContTypeStr);}
TStr GetFldVal(const TStr &FldNm) const
Definition: http.cpp:650
static const TStr ContTypeFldNm
Definition: http.h:12
bool IsStrIn(const TStr &Str) const
Definition: dt.h:557
bool THttpRq::IsFldNm ( const TStr FldNm) const

Definition at line 646 of file http.cpp.

References FldNmToValH, THttpLx::GetNrStr(), and THash< TKey, TDat, THashFunc >::IsKey().

Referenced by ParseHttpRq().

646  {
647  return FldNmToValH.IsKey(THttpLx::GetNrStr(FldNm));
648 }
TStrStrH FldNmToValH
Definition: http.h:74
static TStr GetNrStr(const TStr &Str)
Definition: http.cpp:226
bool IsKey(const TKey &Key) const
Definition: hash.h:258

Here is the call graph for this function:

Here is the caller graph for this function:

bool THttpRq::IsFldVal ( const TStr FldNm,
const TStr FldVal 
) const

Definition at line 659 of file http.cpp.

References GetFldVal(), and THttpLx::GetNrStr().

659  {
660  return THttpLx::GetNrStr(FldVal)==THttpLx::GetNrStr(GetFldVal(FldNm));
661 }
TStr GetFldVal(const TStr &FldNm) const
Definition: http.cpp:650
static TStr GetNrStr(const TStr &Str)
Definition: http.cpp:226

Here is the call graph for this function:

bool THttpRq::IsOk ( ) const
inline

Definition at line 101 of file http.h.

101 {return Ok;}
bool Ok
Definition: http.h:69
static PHttpRq THttpRq::Load ( TSIn )
inlinestatic

Definition at line 95 of file http.h.

References Fail.

95 {Fail; return NULL;}
#define Fail
Definition: bd.h:238
static PHttpRq THttpRq::New ( const PSIn SIn)
inlinestatic

Definition at line 82 of file http.h.

82  {
83  return PHttpRq(new THttpRq(SIn));}
THttpRq(const PSIn &SIn)
Definition: http.cpp:581
TPt< THttpRq > PHttpRq
Definition: http.h:67
static PHttpRq THttpRq::New ( const THttpRqMethod Method,
const PUrl Url,
const TStr ContTypeFldVal,
const TMem BodyMem 
)
inlinestatic

Definition at line 87 of file http.h.

89  {
90  return PHttpRq(new THttpRq(Method, Url, ContTypeFldVal, BodyMem));}
THttpRq(const PSIn &SIn)
Definition: http.cpp:581
THttpRqMethod Method
Definition: http.h:72
TPt< THttpRq > PHttpRq
Definition: http.h:67
static PHttpRq THttpRq::New ( const PUrl Url,
const int &  FetchId = -1 
)
inlinestatic

Definition at line 91 of file http.h.

References hrmGet.

91  {
92  return PHttpRq(new THttpRq(hrmGet, Url, "", TMem(), FetchId));}
Definition: http.h:65
Definition: dt.h:77
THttpRq(const PSIn &SIn)
Definition: http.cpp:581
TPt< THttpRq > PHttpRq
Definition: http.h:67
THttpRq& THttpRq::operator= ( const THttpRq )
inline

Definition at line 98 of file http.h.

References Fail.

98 {Fail; return *this;}
#define Fail
Definition: bd.h:238
void THttpRq::ParseHttpRq ( const PSIn SIn)
private

Definition at line 513 of file http.cpp.

References THash< TKey, TDat, THashFunc >::AddDat(), BodyMem, THttpLx::ClrMemSf(), CompleteP, THttpLx::Eof(), FldNmToValH, TMem::GetAsStr(), THttpLx::GetCrLf(), GetFldVal(), THttpLx::GetFldVal(), THttpLx::GetInt(), TStr::GetInt(), THttpLx::GetMemSf(), THttpLx::GetNrStr(), THttpLx::GetPeriod(), THttpLx::GetRest(), THttpLx::GetRqMethod(), TUrl::GetSearchStr(), THttpLx::GetSpec(), THttpLx::GetToken(), THttpLx::GetUrlStr(), THttpLx::GetWs(), HdStr, heBadUrl, hrmGet, hrmPost, THttpLx::IsCrLf(), IsFldNm(), TUrl::IsOk(), TMem::Len(), MajorVerN, Method, MinorVerN, TUrl::New(), Ok, ParseSearch(), TMem::Trunc(), and Url.

Referenced by THttpRq().

513  {
514  THttpLx Lx(SIn);
515  // initial status
516  Ok=false;
517  CompleteP=false;
518  // request-line
519  Method=Lx.GetRqMethod();
520  Lx.GetWs();
521  //Url=Lx.GetUrl();
522  TStr UrlStr=Lx.GetUrlStr();
523  Lx.GetWs();
524  Lx.GetToken(THttp::HttpStr); Lx.GetSpec(THttp::SlashStr);
525  MajorVerN=Lx.GetInt(1); Lx.GetPeriod(); MinorVerN=Lx.GetInt(1);
526  Lx.GetCrLf();
527  // header fields & values
528  while ((!Lx.Eof())&&(!Lx.IsCrLf())){
529  TStr FldNm=Lx.GetToken(); Lx.GetSpec(THttp::ColonStr);
530  TStr FldVal=Lx.GetFldVal();
531  Lx.GetCrLf();
532  TStr NrFldNm=THttpLx::GetNrStr(FldNm);
533  FldNmToValH.AddDat(NrFldNm, FldVal);
534  }
535  // separator CrLf
536  if (!Lx.IsCrLf()){return;} // to avoid exceptions
537  Lx.GetCrLf();
538  // header & body strings
539  HdStr=Lx.GetMemSf().GetAsStr();
540  Lx.ClrMemSf();
541  Lx.GetRest();
542  BodyMem=Lx.GetMemSf();
543  // completeness
544  int ContLen=GetFldVal(THttp::ContLenFldNm).GetInt(-1);
545  if (ContLen==-1){
546  // if not content-len is given we assume http-request is ok
547  CompleteP=true;
548  } else {
549  if (ContLen<=BodyMem.Len()){
550  // if we read enough data, we claim completeness
551  CompleteP=true;
552  BodyMem.Trunc(ContLen);
553  } else {
554  // if we read not enough data we claim incompleteness
555  CompleteP=false;
556  }
557  }
558  // url
559  if (CompleteP){
560  const TStr LocalBaseUrlStr="http://localhost/";
561  Url=TUrl::New(UrlStr, LocalBaseUrlStr);
562  if (!Url->IsOk()){
563  throw THttpEx(heBadUrl);}
564  }
565  // search string
566  TStr SearchStr;
567  if (Method==hrmGet){
568  SearchStr=Url->GetSearchStr();
569  } else
570  if ((Method==hrmPost)&&(
574  SearchStr=TStr("?")+BodyMem.GetAsStr();
575  }
576  ParseSearch(SearchStr);
577  // at this point ok=true
578  Ok=true;
579 }
int GetInt() const
Definition: dt.h:581
void ParseSearch(const TStr &SearchStr)
Definition: http.cpp:462
TStr GetFldVal(const TStr &FldNm) const
Definition: http.cpp:650
TStrStrH FldNmToValH
Definition: http.h:74
static const TStr ContTypeFldNm
Definition: http.h:12
TStr GetAsStr(const char &NewNullCh='\0') const
Definition: dt.cpp:303
static TStr GetNrStr(const TStr &Str)
Definition: http.cpp:226
static const TStr HttpStr
Definition: http.h:8
int Len() const
Definition: dt.h:134
static PUrl New(const TStr &RelUrlStr, const TStr &BaseUrlStr=TStr())
Definition: url.h:25
bool IsOk(const TUrlScheme _Scheme=usUndef) const
Definition: url.h:32
bool Ok
Definition: http.h:69
Definition: http.h:65
static const TStr ColonStr
Definition: http.h:10
bool CompleteP
Definition: http.h:70
TStr HdStr
Definition: http.h:76
Definition: http.h:65
static const TStr TextHtmlFldVal
Definition: http.h:27
void Trunc(const int &_BfL)
Definition: dt.h:136
static const TStr ContLenFldNm
Definition: http.h:13
static const TStr SlashStr
Definition: http.h:9
PUrl Url
Definition: http.h:73
TStr GetSearchStr() const
Definition: url.h:49
int MinorVerN
Definition: http.h:71
bool IsFldNm(const TStr &FldNm) const
Definition: http.cpp:646
TMem BodyMem
Definition: http.h:77
Definition: dt.h:412
THttpRqMethod Method
Definition: http.h:72
int MajorVerN
Definition: http.h:71
static const TStr AppW3FormFldVal
Definition: http.h:38
TDat & AddDat(const TKey &Key)
Definition: hash.h:238

Here is the call graph for this function:

Here is the caller graph for this function:

void THttpRq::ParseSearch ( const TStr SearchStr)
private

Definition at line 462 of file http.cpp.

References TChA::AddCh(), TUrlEnv::AddToKeyVal(), TChA::Clr(), THttpChRet::Eof(), THttpChRet::GetCh(), TCh::GetHex(), heBadSearchStr, TCh::IsHex(), TStrIn::New(), Ok, and UrlEnv.

Referenced by ParseHttpRq(), and THttpRq().

462  {
463  PSIn SIn=TStrIn::New(SearchStr);
464  THttpChRet ChRet(SIn, heBadSearchStr);
465  try {
466  // check empty search string
467  if (ChRet.Eof()){return;}
468  // require '?' at the beginning
469  if (ChRet.GetCh()!='?'){
470  throw THttpEx(heBadSearchStr);}
471  // parse key=val{&...} pairs
472  TChA KeyNm; TChA ValStr;
473  while (!ChRet.Eof()){
474  char Ch; KeyNm.Clr(); ValStr.Clr();
475  // key
476  while ((Ch=ChRet.GetCh())!='='){
477  switch (Ch){
478  case '%':{
479  char Ch1=ChRet.GetCh();
480  if (!TCh::IsHex(Ch1)) { throw THttpEx(heBadSearchStr); }
481  char Ch2=ChRet.GetCh();
482  if (!TCh::IsHex(Ch2)) { throw THttpEx(heBadSearchStr); }
483  KeyNm.AddCh(char(16*TCh::GetHex(Ch1)+TCh::GetHex(Ch2)));} break;
484  case '+': KeyNm.AddCh(' '); break;
485  case '&': throw THttpEx(heBadSearchStr);
486  default: KeyNm.AddCh(Ch);
487  }
488  }
489  // equals
490  if (Ch!='='){
491  throw THttpEx(heBadSearchStr);}
492  // value
493  while ((!ChRet.Eof())&&((Ch=ChRet.GetCh())!='&')){
494  switch (Ch){
495  case '%':{
496  char Ch1=ChRet.GetCh();
497  if (!TCh::IsHex(Ch1)) { throw THttpEx(heBadSearchStr); }
498  char Ch2=ChRet.GetCh();
499  if (!TCh::IsHex(Ch2)) { throw THttpEx(heBadSearchStr); }
500  ValStr.AddCh(char(16*TCh::GetHex(Ch1)+TCh::GetHex(Ch2)));} break;
501  case '+': ValStr.AddCh(' '); break;
502  case '&': throw THttpEx(heBadSearchStr);
503  default: ValStr.AddCh(Ch);
504  }
505  }
506  // save key-value pair
507  UrlEnv->AddToKeyVal(KeyNm, ValStr);
508  }
509  }
510  catch (const THttpEx&){Ok=false;}
511 }
static bool IsHex(const char &Ch)
Definition: dt.h:1070
void AddToKeyVal(const TStr &KeyNm, const TStr &ValStr)
Definition: url.h:144
void Clr()
Definition: dt.h:258
void AddCh(const char &Ch, const int &MxLen=-1)
Definition: dt.h:271
static int GetHex(const char &Ch)
Definition: dt.h:1072
bool Ok
Definition: http.h:69
static PSIn New(const TStr &Str)
Definition: dt.h:711
Definition: dt.h:201
PUrlEnv UrlEnv
Definition: http.h:75

Here is the call graph for this function:

Here is the caller graph for this function:

void THttpRq::Save ( TSOut )
inline

Definition at line 96 of file http.h.

References Fail.

96 {Fail;}
#define Fail
Definition: bd.h:238

Friends And Related Function Documentation

friend class TPt< THttpRq >
friend

Definition at line 67 of file http.h.

Member Data Documentation

TMem THttpRq::BodyMem
private

Definition at line 77 of file http.h.

Referenced by GetStr(), and ParseHttpRq().

bool THttpRq::CompleteP
private

Definition at line 70 of file http.h.

Referenced by ParseHttpRq().

TCRef THttpRq::CRef
private

Definition at line 67 of file http.h.

TStrStrH THttpRq::FldNmToValH
private

Definition at line 74 of file http.h.

Referenced by AddFldVal(), GetFldVal(), GetFldValH(), GetStr(), IsFldNm(), ParseHttpRq(), and THttpRq().

TStr THttpRq::HdStr
private

Definition at line 76 of file http.h.

Referenced by ParseHttpRq(), and THttpRq().

int THttpRq::MajorVerN
private

Definition at line 71 of file http.h.

Referenced by ParseHttpRq().

THttpRqMethod THttpRq::Method
private

Definition at line 72 of file http.h.

Referenced by GetMethodNm(), and ParseHttpRq().

int THttpRq::MinorVerN
private

Definition at line 71 of file http.h.

Referenced by ParseHttpRq().

bool THttpRq::Ok
private

Definition at line 69 of file http.h.

Referenced by ParseHttpRq(), ParseSearch(), and THttpRq().

PUrl THttpRq::Url
private

Definition at line 73 of file http.h.

Referenced by GetStr(), ParseHttpRq(), and THttpRq().

PUrlEnv THttpRq::UrlEnv
private

Definition at line 75 of file http.h.

Referenced by ParseSearch().


The documentation for this class was generated from the following files: