| 215 | | bool copyFile (IServletContext context, char[] path) |
|---|
| 216 | | { |
|---|
| 217 | | return cacheFile (context, path, null); |
|---|
| 218 | | } |
|---|
| 219 | | |
|---|
| 220 | | /*********************************************************************** |
|---|
| 221 | | |
|---|
| 222 | | ***********************************************************************/ |
|---|
| 223 | | |
|---|
| 224 | | bool cacheFile (IServletContext context, char[] path, IFileCache cache) |
|---|
| | 215 | void copyFile (IServletContext context, char[] path) |
|---|
| | 216 | { |
|---|
| | 217 | cacheFile (context, path, null); |
|---|
| | 218 | } |
|---|
| | 219 | |
|---|
| | 220 | /*********************************************************************** |
|---|
| | 221 | |
|---|
| | 222 | ***********************************************************************/ |
|---|
| | 223 | |
|---|
| | 224 | void cacheFile (IServletContext context, char[] path, IFileCache cache) |
|---|
| 239 | | if (cache) |
|---|
| 240 | | if (cache.get (path, info)) |
|---|
| 241 | | { |
|---|
| 242 | | setHeaders (cast(uint) info.size, info.mime); |
|---|
| 243 | | buffer.append (info.data); |
|---|
| 244 | | return true; |
|---|
| 245 | | } |
|---|
| 246 | | |
|---|
| 247 | | char[512] tmp = void; |
|---|
| 248 | | file.open (context.getResourceAsPath (path, tmp)); |
|---|
| 249 | | scope (exit) |
|---|
| 250 | | file.detach; |
|---|
| 251 | | |
|---|
| 252 | | auto p = Path.parse (path); |
|---|
| 253 | | info.size = cast(ulong) file.length; |
|---|
| 254 | | info.mime = context.getMimeType (p.suffix); |
|---|
| 255 | | setHeaders (cast(uint) info.size, info.mime); |
|---|
| 256 | | |
|---|
| 257 | | // should we cache this? |
|---|
| 258 | | if (cache && cache.put (path, info, file)) |
|---|
| 259 | | buffer.append (info.data); |
|---|
| 260 | | else |
|---|
| 261 | | buffer.copy (file); |
|---|
| 262 | | return true; |
|---|
| 263 | | return false; |
|---|
| | 236 | if (cache) |
|---|
| | 237 | if (cache.get (path, info)) |
|---|
| | 238 | { |
|---|
| | 239 | setHeaders (cast(uint) info.size, info.mime); |
|---|
| | 240 | buffer.append (info.data); |
|---|
| | 241 | return; |
|---|
| | 242 | } |
|---|
| | 243 | |
|---|
| | 244 | char[512] tmp = void; |
|---|
| | 245 | file.open (context.getResourceAsPath (path, tmp)); |
|---|
| | 246 | scope (exit) |
|---|
| | 247 | file.detach; |
|---|
| | 248 | |
|---|
| | 249 | auto p = Path.parse (path); |
|---|
| | 250 | info.size = cast(ulong) file.length; |
|---|
| | 251 | info.mime = context.getMimeType (p.suffix); |
|---|
| | 252 | setHeaders (cast(uint) info.size, info.mime); |
|---|
| | 253 | |
|---|
| | 254 | // should we cache this? |
|---|
| | 255 | if (cache && cache.put (path, info, file)) |
|---|
| | 256 | buffer.append (info.data); |
|---|
| | 257 | else |
|---|
| | 258 | buffer.copy (file); |
|---|