SNAP Library 2.2, Developer Reference  2014-03-11 19:15:55
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
THttpResp Class Reference

#include <http.h>

Collaboration diagram for THttpResp:

List of all members.

Public Member Functions

 THttpResp (const int &_StatusCd, const TStr &ContTypeVal, const bool &CacheCtrlP, const PSIn &BodySIn, const TStr LocStr)
 THttpResp (const PSIn &SIn)
 ~THttpResp ()
 THttpResp (TSIn &)
void Save (TSOut &)
THttpRespoperator= (const THttpResp &)
bool IsOk () const
int Len () const
bool IsContLenOk () const
void GetAsMem (TMem &Mem) const
TStr GetHdStr () const
const TMemGetBodyAsMem () const
TStr GetBodyAsStr () const
PSIn GetBodyAsSIn () const
int GetStatusCd () const
TStr GetReasonPhrase () const
int GetFlds () const
int GetFldVals (const int &FldN) const
void GetFldNmVal (const int &FldN, TStr &FldNm, TStr &FldVal)
void GetFldNmVal (const int &FldN, const int &ValN, TStr &FldNm, TStr &FldVal)
bool IsFldNm (const TStr &FldNm) const
TStr GetFldVal (const TStr &FldNm, const int &ValN=0) const
void GetFldValV (const TStr &FldNm, TStrV &FldValV) const
bool IsFldVal (const TStr &FldNm, const TStr &FldVal) const
void AddFldVal (const TStr &FldNm, const TStr &FldVal)
bool IsStatusCd_Ok () const
bool IsStatusCd_Redir () const
bool IsContType () const
bool IsContType (const TStr &ContTypeStr) const
bool IsContLen (int &ContLen) const
TStr GetSrvNm () const
void GetCookieKeyValDmPathQuV (TStrQuV &CookieKeyValDmPathQuV)
int GetTxtLen () const
void SaveTxt (const PSOut &SOut) const
void SaveBody (const PSOut &SOut) const
PSIn GetSIn () const

Static Public Member Functions

static PHttpResp New (const int &StatusCd, const TStr &ContTypeVal, const bool &CacheCtrlP, const PSIn &BodySIn, const TStr LocStr=TStr())
static PHttpResp New (const PSIn &SIn)
static PHttpResp Load (TSIn &)
static PHttpResp LoadTxt (PSIn &SIn)

Private Member Functions

void AddHdFld (const TStr &FldNm, const TStr &FldVal, TChA &HdChA)
void ParseHttpResp (const PSIn &SIn)

Private Attributes

TCRef CRef
bool Ok
int MajorVerN
int MinorVerN
int StatusCd
TStr ReasonPhrase
TStrStrVH FldNmToValVH
TStr HdStr
TMem BodyMem

Friends

class TPt< THttpResp >

Detailed Description

Definition at line 134 of file http.h.


Constructor & Destructor Documentation

THttpResp::THttpResp ( const int &  _StatusCd,
const TStr ContTypeVal,
const bool &  CacheCtrlP,
const PSIn BodySIn,
const TStr  LocStr 
)

Definition at line 740 of file http.cpp.

References AddHdFld(), BodyMem, TStr::Empty(), TPt< TRec >::Empty(), GetReasonPhrase(), TInt::GetStr(), HdStr, TSIn::Len(), TMem::LoadMem(), MajorVerN, MinorVerN, ReasonPhrase, and StatusCd.

                                                                :
  Ok(true), MajorVerN(1), MinorVerN(0), StatusCd(_StatusCd), ReasonPhrase(),
  FldNmToValVH(20), HdStr(), BodyMem(){
  ReasonPhrase=THttp::GetReasonPhrase(StatusCd);
  TChA HdChA;
  // first line
  HdChA+="HTTP/"; HdChA+=TInt::GetStr(MajorVerN); HdChA+=".";
  HdChA+=TInt::GetStr(MinorVerN); HdChA+=' ';
  HdChA+=TInt::GetStr(StatusCd); HdChA+=' ';
  HdChA+=ReasonPhrase;
  HdChA+="\r\n";
  // header fields
  // server
  //AddHdFld(THttp::SrvFldNm, "Tralala", HdChA);
  if (!LocStr.Empty()){
    AddHdFld("Location", LocStr, HdChA);}
  if (!BodySIn.Empty()){
    // content-type
    AddHdFld(THttp::ContTypeFldNm, ContTypeVal, HdChA);
    // accept-ranges
    AddHdFld(THttp::AcceptRangesFldNm, "bytes", HdChA);
    // content-length
    TStr ContLenVal=TInt::GetStr(BodySIn->Len());
    AddHdFld(THttp::ContLenFldNm, ContLenVal, HdChA);
    // cache-control
    if (!CacheCtrlP){
      AddHdFld(THttp::CacheCtrlFldNm, "no-cache", HdChA);}
  }
  // header/body separator
  HdChA+="\r\n";
  // header/body data
  HdStr=HdChA;
  if (!BodySIn.Empty()){
    TMem::LoadMem(BodySIn, BodyMem);}
}

Here is the call graph for this function:

THttpResp::THttpResp ( const PSIn SIn)

Definition at line 777 of file http.cpp.

References Ok, and ParseHttpResp().

                                   :
  Ok(false), MajorVerN(0), MinorVerN(0), StatusCd(-1), ReasonPhrase(),
  FldNmToValVH(20), HdStr(), BodyMem(){
  try {
    ParseHttpResp(SIn);
  }
  catch (const THttpEx&){Ok=false;}
}

Here is the call graph for this function:

THttpResp::~THttpResp ( ) [inline]

Definition at line 155 of file http.h.

{}
THttpResp::THttpResp ( TSIn ) [inline]

Definition at line 156 of file http.h.

References Fail.

{Fail;}

Member Function Documentation

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

Definition at line 813 of file http.cpp.

References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), FldNmToValVH, THttpLx::GetNrStr(), HdStr, TStr::IsSuffix(), and TChA::Pop().

                                                              {
  TStr NrFldNm=THttpLx::GetNrStr(FldNm);
  FldNmToValVH.AddDat(NrFldNm).Add(FldVal);
  if (HdStr.IsSuffix("\r\n\r\n")){
    TChA HdChA=HdStr;
    HdChA.Pop(); HdChA.Pop(); 
    HdChA+=NrFldNm; HdChA+=": "; HdChA+=FldVal;
    HdChA+="\r\n\r\n";
    HdStr=HdChA;
  }
}

Here is the call graph for this function:

void THttpResp::AddHdFld ( const TStr FldNm,
const TStr FldVal,
TChA HdChA 
) [private]

Definition at line 693 of file http.cpp.

References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), FldNmToValVH, and THttpLx::GetNrStr().

Referenced by THttpResp().

                                                                          {
  TStr NrFldNm=THttpLx::GetNrStr(FldNm);
  FldNmToValVH.AddDat(NrFldNm).Add(FldVal);
  HdChA+=FldNm; HdChA+=": "; HdChA+=FldVal; HdChA+="\r\n";
}

Here is the call graph for this function:

Here is the caller graph for this function:

void THttpResp::GetAsMem ( TMem Mem) const [inline]

Definition at line 166 of file http.h.

References TMem::Clr().

                                 {
    Mem.Clr(); Mem+=HdStr; Mem+=BodyMem;}

Here is the call graph for this function:

const TMem& THttpResp::GetBodyAsMem ( ) const [inline]

Definition at line 169 of file http.h.

{return BodyMem;}
PSIn THttpResp::GetBodyAsSIn ( ) const [inline]

Definition at line 171 of file http.h.

{return BodyMem.GetSIn(); }
TStr THttpResp::GetBodyAsStr ( ) const [inline]

Definition at line 170 of file http.h.

Referenced by TWebPg::IsTxt().

{return BodyMem.GetAsStr(' ');}

Here is the caller graph for this function:

void THttpResp::GetCookieKeyValDmPathQuV ( TStrQuV CookieKeyValDmPathQuV)

Definition at line 825 of file http.cpp.

References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Clr(), TStr::Empty(), GetFldValV(), TStr::GetTrunc(), TStr::IsChIn(), TVec< TVal, TSizeTy >::Len(), TStr::SplitOnAllCh(), and TStr::ToTrunc().

                                                                      {
  CookieKeyValDmPathQuV.Clr();
  TStrV CookieFldValV; GetFldValV(THttp::SetCookieFldNm, CookieFldValV);
  for (int CookieN=0; CookieN<CookieFldValV.Len(); CookieN++){
    TStr CookieFldVal=CookieFldValV[CookieN];
    TStrV KeyValStrV;
    CookieFldVal.SplitOnAllCh(';', KeyValStrV, true);
    TStrPrV KeyValPrV; TStr DmNm; TStr PathStr;
    for (int KeyValStrN=0; KeyValStrN<KeyValStrV.Len(); KeyValStrN++){
      TStr KeyValStr=KeyValStrV[KeyValStrN];
      TStr KeyNm; TStr ValStr; 
      if (KeyValStr.IsChIn('=')){
        KeyValStrV[KeyValStrN].SplitOnCh(KeyNm, '=', ValStr);
        KeyNm.ToTrunc(); ValStr.ToTrunc();
      } else {
        KeyNm=KeyValStr.GetTrunc();
      }
      if (KeyNm=="expires"){}
      else if (KeyNm=="domain"){DmNm=ValStr;}
      else if (KeyNm=="path"){PathStr=ValStr;}
      else if (KeyNm=="expires"){}
      else if (KeyNm=="secure"){}
      else if (KeyNm=="httponly"){}
      else if (!KeyNm.Empty()){
        KeyValPrV.Add(TStrPr(KeyNm, ValStr));
      }
    }
    for (int KeyValPrN=0; KeyValPrN<KeyValPrV.Len(); KeyValPrN++){
      TStr KeyNm=KeyValPrV[KeyValPrN].Val1;
      TStr ValStr=KeyValPrV[KeyValPrN].Val2;
      CookieKeyValDmPathQuV.Add(TStrQu(KeyNm, ValStr, DmNm, PathStr));
    }
  }
}

Here is the call graph for this function:

void THttpResp::GetFldNmVal ( const int &  FldN,
TStr FldNm,
TStr FldVal 
) [inline]

Definition at line 177 of file http.h.

                                                              {
    FldNm=FldNmToValVH.GetKey(FldN); FldVal=FldNmToValVH[FldN][0];}
void THttpResp::GetFldNmVal ( const int &  FldN,
const int &  ValN,
TStr FldNm,
TStr FldVal 
) [inline]

Definition at line 179 of file http.h.

                                                                               {
    FldNm=FldNmToValVH.GetKey(FldN); FldVal=FldNmToValVH[FldN][ValN];}
int THttpResp::GetFlds ( ) const [inline]

Definition at line 174 of file http.h.

{return FldNmToValVH.Len();}
TStr THttpResp::GetFldVal ( const TStr FldNm,
const int &  ValN = 0 
) const

Definition at line 790 of file http.cpp.

References FldNmToValVH, THash< TKey, TDat, THashFunc >::GetDat(), THttpLx::GetNrStr(), THash< TKey, TDat, THashFunc >::IsKey(), and TVec< TVal, TSizeTy >::Len().

Referenced by IsFldVal().

                                                                  {
  TStr NrFldNm=THttpLx::GetNrStr(FldNm);
  if (FldNmToValVH.IsKey(NrFldNm)){
    const TStrV& ValV=FldNmToValVH.GetDat(NrFldNm);
    if (ValV.Len()>0){return ValV[ValN];} else {return TStr();}
  } else {
    return TStr();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int THttpResp::GetFldVals ( const int &  FldN) const [inline]

Definition at line 175 of file http.h.

                                        {
    return FldNmToValVH[FldN].Len();}
void THttpResp::GetFldValV ( const TStr FldNm,
TStrV FldValV 
) const

Definition at line 800 of file http.cpp.

References TVec< TVal, TSizeTy >::Clr(), FldNmToValVH, THash< TKey, TDat, THashFunc >::GetDat(), THttpLx::GetNrStr(), and THash< TKey, TDat, THashFunc >::IsKey().

Referenced by GetCookieKeyValDmPathQuV().

                                                                  {
  TStr NrFldNm=THttpLx::GetNrStr(FldNm);
  if (FldNmToValVH.IsKey(NrFldNm)){
    FldValV=FldNmToValVH.GetDat(NrFldNm);
  } else {
    FldValV.Clr();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

TStr THttpResp::GetHdStr ( ) const [inline]

Definition at line 168 of file http.h.

{return HdStr;}
TStr THttpResp::GetReasonPhrase ( ) const [inline]

Definition at line 173 of file http.h.

References THttp::GetReasonPhrase().

Referenced by THttpResp().

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 860 of file http.cpp.

References BodyMem, HdStr, TMem::Len(), TStr::Len(), and TSOut::PutStr().

                             {
  TMOut MOut(HdStr.Len()+BodyMem.Len());
  MOut.PutStr(HdStr); MOut.PutMem(BodyMem);
  return MOut.GetSIn();
}

Here is the call graph for this function:

TStr THttpResp::GetSrvNm ( ) const [inline]

Definition at line 198 of file http.h.

References THttp::SrvFldNm.

int THttpResp::GetStatusCd ( ) const [inline]

Definition at line 172 of file http.h.

{return StatusCd;}
int THttpResp::GetTxtLen ( ) const [inline]

Definition at line 202 of file http.h.

{return HdStr.Len()+BodyMem.Len();}
bool THttpResp::IsContLen ( int &  ContLen) const [inline]

Definition at line 196 of file http.h.

References THttp::ContLenFldNm.

                                     {
    return GetFldVal(THttp::ContLenFldNm).IsInt(ContLen);}
bool THttpResp::IsContLenOk ( ) const [inline]

Definition at line 164 of file http.h.

                           {int ContLen;
    return IsOk()&&IsContLen(ContLen)&&(ContLen==BodyMem.Len());}
bool THttpResp::IsContType ( ) const [inline]

Definition at line 192 of file http.h.

References THttp::ContTypeFldNm.

Referenced by TWebPg::IsTxt().

Here is the caller graph for this function:

bool THttpResp::IsContType ( const TStr ContTypeStr) const [inline]

Definition at line 194 of file http.h.

References THttp::ContTypeFldNm.

                                                 {
    return GetFldVal(THttp::ContTypeFldNm).IsStrIn(ContTypeStr);}
bool THttpResp::IsFldNm ( const TStr FldNm) const

Definition at line 786 of file http.cpp.

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

                                               {
  return FldNmToValVH.IsKey(THttpLx::GetNrStr(FldNm));
}

Here is the call graph for this function:

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

Definition at line 809 of file http.cpp.

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

                                                                    {
  return THttpLx::GetNrStr(FldVal)==THttpLx::GetNrStr(GetFldVal(FldNm));
}

Here is the call graph for this function:

bool THttpResp::IsOk ( ) const [inline]

Definition at line 162 of file http.h.

{return Ok;}
bool THttpResp::IsStatusCd_Ok ( ) const [inline]

Definition at line 187 of file http.h.

References THttp::OkStatusCd.

                             {
    return IsOk() && (GetStatusCd()/100==THttp::OkStatusCd/100);}
bool THttpResp::IsStatusCd_Redir ( ) const [inline]

Definition at line 189 of file http.h.

References THttp::RedirStatusCd.

                                {
    return IsOk() && (GetStatusCd()/100==THttp::RedirStatusCd/100);}
int THttpResp::Len ( ) const [inline]

Definition at line 163 of file http.h.

{return HdStr.Len()+BodyMem.Len();}
static PHttpResp THttpResp::Load ( TSIn ) [inline, static]

Definition at line 157 of file http.h.

References Fail.

{Fail; return NULL;}
static PHttpResp THttpResp::LoadTxt ( PSIn SIn) [inline, static]

Definition at line 203 of file http.h.

                                     {
    return new THttpResp(SIn);}
static PHttpResp THttpResp::New ( const int &  StatusCd,
const TStr ContTypeVal,
const bool &  CacheCtrlP,
const PSIn BodySIn,
const TStr  LocStr = TStr() 
) [inline, static]

Definition at line 148 of file http.h.

                                                                         {
    return PHttpResp(new
     THttpResp(StatusCd, ContTypeVal, CacheCtrlP, BodySIn, LocStr));}
static PHttpResp THttpResp::New ( const PSIn SIn) [inline, static]

Definition at line 153 of file http.h.

                                       {
    return PHttpResp(new THttpResp(SIn));}
THttpResp& THttpResp::operator= ( const THttpResp ) [inline]

Definition at line 160 of file http.h.

References Fail.

{Fail; return *this;}
void THttpResp::ParseHttpResp ( const PSIn SIn) [private]

Definition at line 699 of file http.cpp.

References TVec< TVal, TSizeTy >::Add(), THash< TKey, TDat, THashFunc >::AddDat(), BodyMem, TMem::Clr(), TStr::Clr(), THttpLx::ClrMemSf(), THttpLx::Eof(), FldNmToValVH, TMem::GetAsStr(), THttpLx::GetCrLf(), THttpLx::GetFldVal(), THttpLx::GetInt(), THttpLx::GetMemSf(), THttpLx::GetNrStr(), THttpLx::GetPeriod(), THttpLx::GetRespReasonPhrase(), THttpLx::GetRest(), THttpLx::GetSpec(), THttpLx::GetToken(), HdStr, THttpLx::IsCrLf(), THttpLx::IsRespStatusLn(), MajorVerN, MinorVerN, Ok, ReasonPhrase, and StatusCd.

Referenced by THttpResp().

                                            {
  THttpLx Lx(SIn);
  if (Lx.Eof()){
    // no content
    MajorVerN=0; MinorVerN=9; StatusCd=204;
    HdStr.Clr(); BodyMem.Clr();
  } else {
    if (Lx.IsRespStatusLn()){
      // status-line
      Lx.GetToken(THttp::HttpStr); Lx.GetSpec(THttp::SlashStr);
      MajorVerN=Lx.GetInt(1); Lx.GetPeriod(); MinorVerN=Lx.GetInt(1);
      StatusCd=Lx.GetInt(3);
      ReasonPhrase=Lx.GetRespReasonPhrase();
      Lx.GetCrLf();
      // header fields & values
      while (!Lx.IsCrLf()){
        TStr FldNm=Lx.GetToken(); Lx.GetSpec(THttp::ColonStr);
        TStr FldVal=Lx.GetFldVal();
        Lx.GetCrLf();
        TStr NrFldNm=THttpLx::GetNrStr(FldNm);
        FldNmToValVH.AddDat(NrFldNm).Add(FldVal);
      }
      // separator CrLf
      Lx.GetCrLf();
      // header & body strings
      HdStr=Lx.GetMemSf().GetAsStr();
      Lx.ClrMemSf();
      Lx.GetRest();
      BodyMem=Lx.GetMemSf();
    } else {
      // old fashion format
      MajorVerN=0; MinorVerN=9; StatusCd=200;
      HdStr.Clr();
      Lx.ClrMemSf();
      Lx.GetRest();
      BodyMem=Lx.GetMemSf();
    }
  }
  Ok=true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void THttpResp::Save ( TSOut ) [inline]

Definition at line 158 of file http.h.

References Fail.

{Fail;}
void THttpResp::SaveBody ( const PSOut SOut) const [inline]

Definition at line 207 of file http.h.

Referenced by TWebPg::SaveAsHttpBody().

                                         {
    BodyMem.SaveMem(SOut);}

Here is the caller graph for this function:

void THttpResp::SaveTxt ( const PSOut SOut) const [inline]

Definition at line 205 of file http.h.

Referenced by TWebPg::SaveAsHttp().

                                        {
    HdStr.SaveTxt(SOut); BodyMem.SaveMem(SOut);}

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class TPt< THttpResp > [friend]

Definition at line 134 of file http.h.


Member Data Documentation

Definition at line 142 of file http.h.

Referenced by GetSIn(), ParseHttpResp(), and THttpResp().

Definition at line 134 of file http.h.

Definition at line 140 of file http.h.

Referenced by AddFldVal(), AddHdFld(), GetFldVal(), GetFldValV(), IsFldNm(), and ParseHttpResp().

Definition at line 141 of file http.h.

Referenced by AddFldVal(), GetSIn(), ParseHttpResp(), and THttpResp().

int THttpResp::MajorVerN [private]

Definition at line 137 of file http.h.

Referenced by ParseHttpResp(), and THttpResp().

int THttpResp::MinorVerN [private]

Definition at line 137 of file http.h.

Referenced by ParseHttpResp(), and THttpResp().

bool THttpResp::Ok [private]

Definition at line 136 of file http.h.

Referenced by ParseHttpResp(), and THttpResp().

Definition at line 139 of file http.h.

Referenced by ParseHttpResp(), and THttpResp().

int THttpResp::StatusCd [private]

Definition at line 138 of file http.h.

Referenced by ParseHttpResp(), and THttpResp().


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