Return Type | Function name | Arguments |
---|---|---|
hzEcode | hzHttpEvent::SendFilePage | (const char*,const char*,unsigned int,bool,) |
Declared in file: hzHttpServer.h
Defined in file : hzHttpServer.cpp
Function Logic:
Function body:
hzEcode hzHttpEvent::SendFilePage (const char* cpDir, const char* cpFilename, unsigned int nExpires, bool bZip) { _hzfunc("hzHttpEvent::SendFilePage") ; ifstream is ; FSTAT fs ; hzChain Z ; const char* pEnd ; hzString Pagename ; hzMimetype type ; hzEcode rc ; if (cpDir && cpDir[0]) { Z << cpDir ; Z.AddByte(CHAR_FWSLASH) ; } if (!cpFilename || !cpFilename[0]|| (cpFilename[0]== CHAR_FWSLASH && cpFilename[1]== 0)) Z += "index.html" ; else Z += cpFilename ; Pagename = Z ; Z.Clear() ; if (lstat(*Pagename, &fs) == -1) { SendError(HTTPMSG_NOTFOUND, "Could not locate %s\n", *Pagename) ; return E_NOTFOUND ; } pEnd = strrchr(*Pagename, CHAR_PERIOD) ; if (!pEnd) type = HMTYPE_TXT_PLAIN ; else type = Filename2Mimetype(pEnd) ; is.open(*Pagename) ; if (is.fail()) { SendError(HTTPMSG_NOTFOUND, "Could not open requested file (%s\n", *Pagename) ; return E_OPENFAIL ; } Z += is ; is.close() ; if (!Z.Size()) { SendError(HTTPMSG_NOTFOUND, "File (%s) of zero size\n", *Pagename) ; return E_NODATA ; } rc = SendRawChain(HTTPMSG_OK, type, Z, nExpires, bZip) ; if (rc != E_OK) { hzerr(E_WRITEFAIL, "Response data not sent to browser (sock=%d)", m_pCx->CliSocket()) ; return E_WRITEFAIL ; } return E_OK ; }