Ejemplo n.º 1
0
        public async Task Invoke(HttpContext httpContext, IValidatorValueInvalidator validatorValueInvalidator)
        {
            // Use method injection for IValidatorValueInvalidator, as it's a scoped service.  Only singleton
            // services can be injected via constructor injection when working with middleware

            _validatorValueInvalidator = validatorValueInvalidator
                                         ?? throw new ArgumentNullException(nameof(validatorValueInvalidator));

            var hasHttpCacheIgnoreAttribute = httpContext.GetEndpoint()?.Metadata
                                              .Any(m => m is HttpCacheIgnoreAttribute);

            if (hasHttpCacheIgnoreAttribute.HasValue && hasHttpCacheIgnoreAttribute.Value)
            {
                // continue with the next delegate in line
                await _next.Invoke(httpContext);

                return;
            }

            // check request ETag headers & dates
            if (await GetOrHeadIndicatesResourceStillValid(httpContext))
            {
                // don't continue with the next delegate in line, a response (304) has been generated
                return;
            }

            if (await PutOrPostIndicatesResourceHasChanged(httpContext))
            {
                // don't continue with the next delegate in line, a response (412) has been generated
                return;
            }

            await HandleResponse(httpContext);
        }
Ejemplo n.º 2
0
 public StoreManipulationController(
     IValidatorValueInvalidator validatorValueInvalidator,
     IStoreKeyAccessor storeKeyAccessor)
 {
     _validatorValueInvalidator = validatorValueInvalidator
                                  ?? throw new ArgumentNullException(nameof(validatorValueInvalidator));
     _storeKeyAccessor = storeKeyAccessor
                         ?? throw new ArgumentNullException(nameof(storeKeyAccessor));
 }
Ejemplo n.º 3
0
        public async Task Invoke(HttpContext httpContext, IValidatorValueInvalidator validatorValueInvalidator)
        {
            // Use method injection for IValidatorValueInvalidator, as it's a scoped service.  Only singleton
            // services can be injected via constructor injection when working with middleware

            _validatorValueInvalidator = validatorValueInvalidator
                                         ?? throw new ArgumentNullException(nameof(validatorValueInvalidator));

            // check request ETag headers & dates
            if (await GetOrHeadIndicatesResourceStillValid(httpContext))
            {
                return;
            }

            if (await PutOrPostIndicatesResourceHasChanged(httpContext))
            {
                return;
            }

            await HandleResponse(httpContext);
        }
Ejemplo n.º 4
0
        public async Task Invoke(HttpContext httpContext, IValidatorValueInvalidator validatorValueInvalidator)
        {
            var requestPath = httpContext.Request.Path.Value;

            if (!string.IsNullOrWhiteSpace(requestPath))
            {
                var noCache = _excludedRouteModelOptions.Routes.Any(part =>
                                                                    requestPath.Contains(part, StringComparison.InvariantCultureIgnoreCase));
                if (noCache)
                {
                    // Call the next middleware delegate in the pipeline
                    await _next.Invoke(httpContext);

                    return;
                }
            }

            // Use method injection for IValidatorValueInvalidator, as it's a scoped service.  Only singleton
            // services can be injected via constructor injection when working with middleware

            _validatorValueInvalidator = validatorValueInvalidator
                                         ?? throw new ArgumentNullException(nameof(validatorValueInvalidator));

            // check request ETag headers & dates
            if (await GetOrHeadIndicatesResourceStillValid(httpContext))
            {
                return;
            }

            // Let backend check precondition
            //if (await PutOrPostIndicatesResourceHasChanged(httpContext))
            //{
            //    return;
            //}

            await HandleResponse(httpContext);
        }