void ServeImage(IManosContext ctx, string path)
{
string etag, fileEtag;
if (ctx.Request.Headers.TryGetNormalizedValue ("If-None-Match", out etag)
&& etagCache.TryGetValue (path, out fileEtag)
&& fileEtag.Equals (etag, StringComparison.Ordinal)) {
ctx.Response.StatusCode = 304;
ctx.Response.End ();
return;
}
if (File.Exists (path)) {
ctx.Response.Headers.SetNormalizedHeader ("Content-Type", "image/jpeg");
ctx.Response.Headers.SetNormalizedHeader ("Expires", expires);
ctx.Response.Headers.SetNormalizedHeader ("Cache-Control", cacheControl);
if (!etagCache.ContainsKey (path))
etagCache[path] = GetEtagFromFile (path);
ctx.Response.Headers.SetNormalizedHeader ("ETag", etagCache[path]);
ctx.Response.SendFile (path);
} else
ctx.Response.StatusCode = 404;
ctx.Response.End ();
}