Return TypeFunction nameArguments
hzEcodehzHttpEvent::SendFileHead(const char*,const char*,unsigned int,)

Declared in file: hzHttpServer.h
Defined in file : hzHttpServer.cpp

Function Logic:

0:START 1:Pathname 2:cpFilename[0]==(char)47&&cpFilename[1]==0 3:Pathname 4:cpFilename[0]==(char)47 5:Pathname 6:Pathname Pathname 7:stat(*Pathname,&fs)==-1 8:hrc nLen 9:hrc nLen 10:strrchr pEnd 11:!pEnd 12:type 13:Filename2Mimetype type 14:hzHttpEvent::_formhead rc 15:rc!=E_OK 16:hzIpConnex::CliSocket 17:Return rc 18:m_pCx->SendData(Z)!=E_OK 19:hzIpConnex::CliSocket 20:Return E_WRITEFAIL 21:Return E_OK

Function body:

hzEcode hzHttpEvent::SendFileHead (const char* cpDir, const char* cpFilename, unsigned int nExpires)
{
   _hzfunc("hzHttpEvent::SendFileHead") ;
   ifstream    is ;
   FSTAT       fs ;
   hzXDate     d ;
   hzChain     Z ;
   const char* pEnd ;
   hzString    Pathname ;
   uint32_t    nLen = 0;
   hzMimetype  type ;
   HttpRC      hrc ;
   hzEcode     rc ;
   Pathname = cpDir ;
   if (cpFilename[0]== CHAR_FWSLASH && cpFilename[1]== 0)
       Pathname += "/index.html" ;
   else
   {
       if (cpFilename[0]== CHAR_FWSLASH)
           Pathname += cpFilename ;
       else
       {
           Pathname += "/" ;
           Pathname += cpFilename ;
       }
   }
   if (stat(*Pathname, &fs) == -1)
   {
       hrc = HTTPMSG_NOTFOUND ;
       nLen = 0;
   }
   else
   {
       hrc = HTTPMSG_OK ;
       nLen = fs.st_size ;
   }
   pEnd = strrchr(*Pathname, CHAR_PERIOD) ;
   if (!pEnd)
       type = HMTYPE_TXT_PLAIN ;
   else
       type = Filename2Mimetype(pEnd) ;
   rc = _formhead(Z, hrc, type, nLen, nExpires, false) ;
   if (rc != E_OK)
   {
       hzerr(rc, "Could not formulate HTTP header (sock=%d)", m_pCx->CliSocket()) ;
       return rc ;
   }
   if (m_pCx->SendData(Z) != E_OK)
   {
       hzerr(E_WRITEFAIL, "hzHttpEvent %p Failed to send response to browser (sock=%d)", this, m_pCx->CliSocket()) ;
       return E_WRITEFAIL ;
   }
   return E_OK ;
}