Exemplo n.º 1
0
        /// <summary>
        /// Handles the tus.io request.
        /// </summary>
        /// <param name="context">The IOwinContext</param>
        /// <returns></returns>
        public override async Task Invoke(IOwinContext context)
        {
            var request = new RequestAdapter
            {
                Headers    = context.Request.Headers.ToDictionary(f => f.Key, f => f.Value.ToList(), StringComparer.OrdinalIgnoreCase),
                Body       = context.Request.Body,
                Method     = context.Request.Method,
                RequestUri = context.Request.Uri
            };

            var response = new ResponseAdapter
            {
                Body      = context.Response.Body,
                SetHeader = (key, value) => context.Response.Headers[key] = value,
                SetStatus = status => context.Response.StatusCode = status
            };

            var config = _configFactory(context.Request);

            var handled = await TusProtocolHandler.Invoke(new ContextAdapter
            {
                Request           = request,
                Response          = response,
                Configuration     = config,
                CancellationToken = context.Request.CallCancelled
            });

            if (!handled)
            {
                await Next.Invoke(context);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the tus.io request.
        /// </summary>
        /// <param name="context">The HttpContext</param>
        /// <returns></returns>
        public async Task Invoke(HttpContext context)
        {
            var request = new RequestAdapter
            {
                Headers =
                    context.Request.Headers.ToDictionary(
                        f => f.Key,
                        f => f.Value.ToList(),
                        StringComparer.OrdinalIgnoreCase),
                Body       = context.Request.Body,
                Method     = context.Request.Method,
                RequestUri = new Uri(
                    $"{context.Request.Scheme}://{context.Request.Host}{context.Request.Path}")
            };

            var response = new ResponseAdapter
            {
                Body      = context.Response.Body,
                SetHeader = (key, value) => context.Response.Headers[key] = value,
                SetStatus = status => context.Response.StatusCode = status
            };

            var config = _configFactory(context);

            var handled = await TusProtocolHandler.Invoke(
                new ContextAdapter
            {
                Request           = request,
                Response          = response,
                CancellationToken = context.RequestAborted,
                Configuration     = config,
            });


            if (!handled)
            {
                await _next(context);
            }
        }