public Yield GetFileOrFolderListing(DreamContext context, DreamMessage request, Result <DreamMessage> response) { var head = "HEAD".EqualsInvariant(context.Verb); var path = GetPath(context); var data = _s3Client.GetDataInfo(path, head); DreamMessage result; if (data == null) { response.Return(DreamMessage.NotFound("no such file or folder")); yield break; } if (data.IsDirectory) { // Note (arnec): HEAD for a directory doesn't really mean anything, so we just return ok, to indicate that it exists result = head ? DreamMessage.Ok() : DreamMessage.Ok(data.AsDirectoryDocument()); } else { // dealing with a file request var filehandle = data.AsFileHandle(); // check if request contains a 'if-modified-since' header if (request.CheckCacheRevalidation(filehandle.Modified) && (filehandle.Modified.Year >= 1900)) { response.Return(DreamMessage.NotModified()); yield break; } result = head ? new DreamMessage(DreamStatus.Ok, null, filehandle.MimeType, filehandle.Size, Stream.Null) : DreamMessage.Ok(filehandle.MimeType, filehandle.Size, filehandle.Stream); // add caching headers if file was found if (!head && result.IsSuccessful) { // add caching information; this will avoid unnecessary data transfers by user-agents with caches result.SetCacheMustRevalidate(filehandle.Modified); } } response.Return(result); yield break; }
public AmazonS3DataInfo GetDataInfo(string path, bool head) { return(Client.GetDataInfo(path, head)); }