| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzHttpEvent::SendFileHead | (const char*,const char*,unsigned int,) |
Declared in file: hzHttpServer.h
Defined in file : hzHttpServer.cpp
Function Logic:
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 ;
}