summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2012-04-24 19:27:37 +0000
committerrandomdan <randomdan@localhost>2012-04-24 19:27:37 +0000
commit729a17340a556193d33c150bbc1236eae085916a (patch)
tree9204f7eeb13740da7bc37d60e2cbf4c418a700d5
parentAdd support for using boost::format for log messages (diff)
downloadproject2-729a17340a556193d33c150bbc1236eae085916a.tar.bz2
project2-729a17340a556193d33c150bbc1236eae085916a.tar.xz
project2-729a17340a556193d33c150bbc1236eae085916a.zip
Include content length when serving static content
-rw-r--r--project2/cgi/cgiAppEngine.cpp1
-rw-r--r--project2/common/transform.h1
-rw-r--r--project2/files/presenterCache.cpp6
3 files changed, 8 insertions, 0 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp
index c7ee3e6..ea50627 100644
--- a/project2/cgi/cgiAppEngine.cpp
+++ b/project2/cgi/cgiAppEngine.cpp
@@ -67,6 +67,7 @@ class StaticToCgiResult : public TransformImpl<StaticContent, CgiResult> {
public:
void transform(const StaticContent * sc, CgiResult * cr) const {
cr->header->addHeader("Content-Type", Glib::ustring::compose("%1; charset=%2", sc->getContentType(), sc->getEncoding()));
+ cr->header->addHeader("Content-Length", Glib::ustring::compose("%1", sc->getSizeInBytes()));
cr->header->render(cr->stream);
sc->writeTo(cr->stream);
}
diff --git a/project2/common/transform.h b/project2/common/transform.h
index 2355195..b7a724a 100644
--- a/project2/common/transform.h
+++ b/project2/common/transform.h
@@ -81,6 +81,7 @@ class StaticContent {
public:
virtual Glib::ustring getContentType() const = 0;
virtual Glib::ustring getEncoding() const = 0;
+ virtual size_t getSizeInBytes() const = 0;
virtual void writeTo(std::ostream &) const = 0;
};
diff --git a/project2/files/presenterCache.cpp b/project2/files/presenterCache.cpp
index 8d189b5..8838568 100644
--- a/project2/files/presenterCache.cpp
+++ b/project2/files/presenterCache.cpp
@@ -77,6 +77,12 @@ class FilePresenterCache : public PresenterCache, public StaticContent, public S
buf[safesys<CacheFileXAttr>(-1, fgetxattr(readcachefd, "user.content-type", buf, sizeof(buf)))] = 0;
return buf;
}
+ size_t getSizeInBytes() const
+ {
+ struct stat st;
+ safesys<CacheFileXAttr>(-1, fstat(readcachefd, &st));
+ return st.st_size;
+ }
void writeTo(std::ostream & o) const
{
safesys<LockCacheFile>(-1, ::flock(readcachefd, LOCK_SH));