Ejemplo n.º 1
0
void TWebPgFetchEvent::OnFetchEnd(const PHttpResp& HttpResp){
  EAssert(HttpResp->IsOk());
  EndMSecs=TTm::GetCurUniMSecs();
  int StatusCd=HttpResp->GetStatusCd();
  if (StatusCd/100==2){ // codes 2XX - ok
    ChangeLastUrlToLc(HttpResp);
    PWebPg WebPg=TWebPg::New(UrlStrV, IpNumV, HttpResp);
    WebPg->PutFetchMSecs(GetFetchMSecs());
    CloseConn(); Fetch->DisconnUrl(FId);
    Fetch->OnFetch(FId, WebPg);
  } else
  if (StatusCd/100==3){ // codes 3XX - redirection
    ChangeLastUrlToLc(HttpResp);
    if (UrlStrV.Len()<5){
      TStr RedirUrlStr=HttpResp->GetFldVal("Location");
      PUrl RedirUrl=TUrl::New(RedirUrlStr, CurUrl->GetUrlStr());
      if (RedirUrl->IsOk(usHttp)){
        TStrQuV CookieQuV; HttpResp->GetCookieKeyValDmPathQuV(CookieQuV);
        AddCookieKeyValDmPathQuV(CookieQuV);
        CurUrl=RedirUrl; Retries=0; CloseConn();
        TSockHost::GetAsyncSockHost(CurUrl->GetIpNumOrHostNm(), this);
      } else {
        TStr MsgStr=TStr("Invalid Redirection URL (")+RedirUrlStr+")";
        OnFetchError(MsgStr);
      }
    } else {
      TStr MsgStr=TStr("Cycling Redirection [")+TopUrl->GetUrlStr()+"]";
      OnFetchError(MsgStr);
    }
  } else { // all other codes - error
    TStr MsgStr=TStr("Http Error (")+
     TInt::GetStr(StatusCd)+"/"+HttpResp->GetReasonPhrase()+")";
    OnFetchError(MsgStr);
  }
}
Ejemplo n.º 2
0
void TWebPgFetch::OpenConn(const int& FId, const PUrl& Url){
  PSockEvent Event=PSockEvent(new TWebPgFetchEvent(this, FId, Url, ProxyStr, UserAgentStr, TimeOutMSecs));
  TSockEvent::Reg(Event);
  ConnFIdToEventH.AddDat(FId, Event);
  TStr HostNm;
  if (ProxyStr.Empty()){HostNm=Url->GetIpNumOrHostNm();}
  else {TStr PortNStr; ProxyStr.SplitOnCh(HostNm, ':', PortNStr);}
  TSockHost::GetAsyncSockHost(HostNm, Event);
}