Example #1
0
        public void WeakEtag()
        {
            ETagBuilder b = CreateBuilder();

            b.Set("\"myetag\"", true);
            Assert.Equal("W/\"myetag\"", b.Build());
        }
Example #2
0
        public async Task <IActionResult> GetById(string myProductId)
        {
            // Example of using the query builder
            var result = await MyProductRepository.GetAsync(myProductId);

            if (result == null)
            {
                return(NotFound());
            }

            // Generate a etag for the entity to allow client side caching based on this.
            var eTag = new ETagBuilder()
                       .WithToken(result.MyProductId)
                       .WithToken(result.Name)
                       .WithToken(result.Description)
                       .Build();

            // Check for conditions from request headers
            var action = RequestPreconditionCheck()
                         .WithETag(eTag)
                         .WithLastModified(result.Modified)
                         .GetRecommendedAction();

            if (action != null)
            {
                return(action);
            }

            return(Json(result).WithETag(eTag).WithLastModified(result.Modified));
        }
Example #3
0
        public void SimpleEtag()
        {
            ETagBuilder b = CreateBuilder();

            b.Set("\"myetag\"");
            Assert.Equal("\"myetag\"", b.Build());

            b.Reset();
            Assert.Null(b.Build());
        }
Example #4
0
 public GetObjectRequest(string bucketName, string resource) : base(HttpMethod.GET, bucketName, resource)
 {
     Range                      = new RangeBuilder();
     IfETagMatch                = new ETagBuilder();
     IfETagNotMatch             = new ETagBuilder();
     ResponseCacheControl       = new CacheControlBuilder();
     ResponseContentType        = new ContentTypeBuilder();
     ResponseContentDisposition = new ContentDispositionBuilder();
     ResponseContentLanguage    = new ContentLanguageBuilder();
     ResponseContentEncoding    = new ContentEncodingBuilder();
 }
Example #5
0
 internal HeadObjectRequest() : base(HttpMethod.HEAD)
 {
     Range                      = new RangeBuilder();
     IfETagMatch                = new ETagBuilder();
     IfETagNotMatch             = new ETagBuilder();
     ResponseCacheControl       = new CacheControlBuilder();
     ResponseContentType        = new ContentTypeBuilder();
     ResponseContentDisposition = new ContentDispositionBuilder();
     ResponseContentLanguage    = new ContentLanguageBuilder();
     ResponseContentEncoding    = new ContentEncodingBuilder();
 }
Example #6
0
        public async Task <IActionResult> Put([FromBody] MyProduct value)
        {
            // Sample validation on the model
            // In reality, validation should be in the model layer and not controller
            if (string.IsNullOrEmpty(value.MyProductId))
            {
                return(BadRequest("MyProductId is required!"));
            }

            // First try get the resource to update
            var toUpdate = AllMyProducts.FirstOrDefault(p => p.MyProductId == value.MyProductId);

            if (toUpdate == null)
            {
                return(NotFound());
            }

            // Generate a etag for the entity to update
            var originalETag = new ETagBuilder()
                               .WithToken(toUpdate.MyProductId)
                               .WithToken(toUpdate.Name)
                               .WithToken(toUpdate.Description)
                               .Build();

            // Check for conditions from request headers
            var action = RequestPreconditionCheck()
                         .WithETag(originalETag)
                         .WithLastModified(toUpdate.Modified)
                         .GetRecommendedAction();

            if (action != null)
            {
                return(action);
            }

            // Now update the resource (fake it here by removing and adding)
            AllMyProducts.Remove(toUpdate);
            AllMyProducts.Add(value);

            // Generate a etag for the new entity
            var eTag = new ETagBuilder()
                       .WithToken(value.MyProductId)
                       .WithToken(value.Name)
                       .WithToken(value.Description)
                       .Build();

            // Construct the response as 200 OK (or 204 No Content), with right headers attached
            return(Json(value).WithETag(eTag).WithLastModified(value.Modified));
        }
Example #7
0
        internal CopyObjectRequest() : base(HttpMethod.PUT)
        {
            MetadataDirective = MetadataDirective.Copy;
            TaggingDirective  = TaggingDirective.Copy;

            AclGrantRead        = new AclBuilder();
            AclGrantReadAcp     = new AclBuilder();
            AclGrantWriteAcp    = new AclBuilder();
            AclGrantFullControl = new AclBuilder();
            IfETagNotMatch      = new ETagBuilder();
            IfETagMatch         = new ETagBuilder();
            Metadata            = new MetadataBuilder();
            Tags       = new TagBuilder();
            SseContext = new KmsContextBuilder();
        }
Example #8
0
    internal HeadObjectRequest(HttpMethodType method) : base(method)
    {
        Range                = new RangeBuilder();
        IfETagMatch          = new ETagBuilder();
        IfETagNotMatch       = new ETagBuilder();
        ResponseCacheControl = new CacheControlBuilder();
        ResponseContentType  = new ContentTypeBuilder();

        //Amazon does not support the extended filename RFC in their presigned requests
        ContentDispositionOptions contentDisp = new ContentDispositionOptions();

        contentDisp.UseExtendedFilename = false;

        ResponseContentDisposition = new ContentDispositionBuilder(Options.Create(contentDisp));
        ResponseContentLanguage    = new ContentLanguageBuilder();
        ResponseContentEncoding    = new ContentEncodingBuilder();
    }
Example #9
0
 public Download WithEtagConditional(ETagBuilder ifETagMatch = null, ETagBuilder ifETagNotMatch = null)
 {
     _request.IfETagMatch    = ifETagMatch;
     _request.IfETagNotMatch = ifETagNotMatch;
     return(this);
 }