Changeset 1115

Show
Ignore:
Timestamp:
07/10/08 01:05:51 (5 months ago)
Author:
kris
Message:

fixed cacheFile() returns

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/mango/net/servlet/ServletResponse.d

    r1114 r1115  
    222222        ***********************************************************************/ 
    223223 
    224         void cacheFile (IServletContext context, char[] path, IFileCache cache) 
     224        bool cacheFile (IServletContext context, char[] path, IFileCache cache) 
    225225        { 
    226226                cache.Info info; 
     
    229229                if (file is null)    
    230230                    file = new FileConduit; 
    231  
    232                 scope (failure) 
    233                       sendError (HttpResponses.NotFound); 
    234231 
    235232                auto log = (cast(ServletContext) context).log; 
     
    239236                       setHeaders (cast(uint) info.size, info.mime); 
    240237                       buffer.append (info.data); 
    241                        return
     238                       return true
    242239                       } 
    243240 
    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); 
     241                try { 
     242                    char[512] tmp = void; 
     243                    file.open (context.getResourceAsPath (path, tmp)); 
     244 
     245                    auto p = Path.parse (path); 
     246                    info.size = cast(ulong) file.length; 
     247                    info.mime = context.getMimeType (p.suffix); 
     248                    setHeaders (cast(uint) info.size, info.mime); 
     249 
     250                    // should we cache this? 
     251                    if (cache && cache.put (path, info, file)) 
     252                        buffer.append (info.data); 
     253                    else 
     254                       buffer.copy (file); 
     255                    } catch (IOException e) 
     256                            { 
     257                            sendError (HttpResponses.NotFound); 
     258                            return false; 
     259                            } 
     260                      finally 
     261                            { 
     262                            file.detach; 
     263                            } 
     264                return true; 
    259265        } 
    260266} 
  • trunk/mango/net/servlet/model/IServletResponse.d

    r1114 r1115  
    139139        ***********************************************************************/ 
    140140 
    141         void cacheFile (IServletContext context, char[] path, IFileCache cache); 
     141        bool cacheFile (IServletContext context, char[] path, IFileCache cache); 
    142142}