E
earl.bobby
I'm creating a webserver to run from a CD. I've found
http://www.adp-gmbh.ch/win/misc/webserver.html which is my starting
block. I've really made two modifications. First adding the
appropriate content-type in the headers whether I'm delivering
html/css/jpeg/etc. The second is reading those simple html/css files
as opposed to having the html hard coded. My problem occurs when
trying to display flash files. I am also only able to reproduce the
problem in IE, not Firefox. Trying to view the swf prompts for a
download of the file, which does fail if you try it. I know this isn't
some setting in IE b/c other swf's load fine.
My best guess is how I'm reading the files?
I've included below the two code modifications from the original
source.
main.cpp.......... Read Files instead of hard coding html
std::string strLine;
std::string strResponse;
std::string strChapter = r->path_;
ifstream objFile;
// COMMENT: Process Empty Request
if (strChapter == "/")
{ strChapter = "/index.htm"; }
// COMMENT: Add TSLM Directory, Remove Leading Slash
strChapter = "tslm\\" + strChapter.substr(1,strChapter.length());
// COMMENT: Open File
objFile.open(strChapter.c_str(), ios:ut | ios::binary);
if (objFile.is_open())
{
// COMMENT: Loop Through File
while (!objFile.eof())
{
getline (objFile,strLine);
strResponse += strLine + "\n";
}
// COMMENT: Close Binary Connection
objFile.close();
}
else
{ strResponse = ""; }
// COMMENT: Return Response
r->answer_ = strResponse;
WebServer.cpp...... Fixed Content-Type Headers...
// COMMENT: Determine Content Type
if(strExt == (".htm") || strExt == (".html"))
strType = "text/html";
else if(strExt == (".css"))
strType = "text/css";
else if(strExt == (".js"))
strType = "application/x-javascript";
else if(strExt == (".swf"))
strType = "application/x-shockwave-flash";
else if(strExt == (".txt"))
strType = "text/plain";
else if(strExt == (".jpg") || strExt == (".jpeg"))
strType = "image/jpeg";
else if(strExt == (".gif"))
strType = "image/gif";
else
strType = "application/octet-stream";
Any help or insight as to why this fails would be more than appreciated!
http://www.adp-gmbh.ch/win/misc/webserver.html which is my starting
block. I've really made two modifications. First adding the
appropriate content-type in the headers whether I'm delivering
html/css/jpeg/etc. The second is reading those simple html/css files
as opposed to having the html hard coded. My problem occurs when
trying to display flash files. I am also only able to reproduce the
problem in IE, not Firefox. Trying to view the swf prompts for a
download of the file, which does fail if you try it. I know this isn't
some setting in IE b/c other swf's load fine.
My best guess is how I'm reading the files?
I've included below the two code modifications from the original
source.
main.cpp.......... Read Files instead of hard coding html
std::string strLine;
std::string strResponse;
std::string strChapter = r->path_;
ifstream objFile;
// COMMENT: Process Empty Request
if (strChapter == "/")
{ strChapter = "/index.htm"; }
// COMMENT: Add TSLM Directory, Remove Leading Slash
strChapter = "tslm\\" + strChapter.substr(1,strChapter.length());
// COMMENT: Open File
objFile.open(strChapter.c_str(), ios:ut | ios::binary);
if (objFile.is_open())
{
// COMMENT: Loop Through File
while (!objFile.eof())
{
getline (objFile,strLine);
strResponse += strLine + "\n";
}
// COMMENT: Close Binary Connection
objFile.close();
}
else
{ strResponse = ""; }
// COMMENT: Return Response
r->answer_ = strResponse;
WebServer.cpp...... Fixed Content-Type Headers...
// COMMENT: Determine Content Type
if(strExt == (".htm") || strExt == (".html"))
strType = "text/html";
else if(strExt == (".css"))
strType = "text/css";
else if(strExt == (".js"))
strType = "application/x-javascript";
else if(strExt == (".swf"))
strType = "application/x-shockwave-flash";
else if(strExt == (".txt"))
strType = "text/plain";
else if(strExt == (".jpg") || strExt == (".jpeg"))
strType = "image/jpeg";
else if(strExt == (".gif"))
strType = "image/gif";
else
strType = "application/octet-stream";
Any help or insight as to why this fails would be more than appreciated!