Ejemplo n.º 1
0
        public Task Invoke(HttpContext context)
        {
            // Detect if an opaque upgrade is available. If so, add a websocket upgrade.
            var upgradeFeature = context.Features.Get <IHttpUpgradeFeature>();

            if (upgradeFeature != null && context.Features.Get <IHttpWebSocketFeature>() == null)
            {
                var webSocketFeature = new UpgradeHandshake(context, upgradeFeature, _options);
                context.Features.Set <IHttpWebSocketFeature>(webSocketFeature);

                if (!_anyOriginAllowed)
                {
                    // Check for Origin header
                    var originHeader = context.Request.Headers[HeaderNames.Origin];

                    if (!StringValues.IsNullOrEmpty(originHeader) && webSocketFeature.IsWebSocketRequest)
                    {
                        // Check allowed origins to see if request is allowed
                        if (!_allowedOrigins.Contains(originHeader.ToString(), StringComparer.Ordinal))
                        {
                            _logger.LogDebug("Request origin {Origin} is not in the list of allowed origins.", originHeader);
                            context.Response.StatusCode = StatusCodes.Status403Forbidden;
                            return(Task.CompletedTask);
                        }
                    }
                }
            }

            return(_next(context));
        }
Ejemplo n.º 2
0
        public Task InvokeAsync(
            HttpContext context,
            RequestDelegate next)
        {
            // Detect if an opaque upgrade is available. If so, add a spdy upgrade.
            var upgradeFeature = context.Features.Get <IHttpUpgradeFeature>();

            if (upgradeFeature != null &&
                context.Features.Get <ISpdyFeature>() == null)
            {
                var spdyFeature = new UpgradeHandshake(context, upgradeFeature);
                context.Features.Set <ISpdyFeature>(spdyFeature);
            }

            return(next.Invoke(context));
        }
Ejemplo n.º 3
0
        public Task InvokeAsync(
            HttpContext context,
            RequestDelegate next)
        {
            // Detect if an opaque upgrade is available. If so, add a spdy upgrade.
            var upgradeFeature = context.Features.Get <IHttpUpgradeFeature>();

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse Can be null
            if (upgradeFeature != null &&
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse Can be null
                context.Features.Get <ISpdyFeature>() == null)
            {
                var spdyFeature = new UpgradeHandshake(context, upgradeFeature);
                context.Features.Set <ISpdyFeature>(spdyFeature);
            }

            return(next.Invoke(context));
        }