Пример #1
0
        public Task InvokeAsync(HttpContext context)
        {
            if (string.IsNullOrEmpty(_prefix.Value) || context.Request.Path.StartsWithSegments(_prefix))
            {
                var script = RequestContextCore.ResolveScript(context.Request, out var path_info);
                if (script.IsValid)
                {
                    return(InvokeScriptAsync(context, script, path_info));
                }
            }

            //
            return(_next(context));
        }
Пример #2
0
        public Task InvokeAsync(HttpContext context)
        {
            if (context.Request.Path.StartsWithSegments(_prefix))
            {
                var script = RequestContextCore.ResolveScript(context.Request);
                if (script.IsValid)
                {
                    return(InvokeScriptAsync(context, script));
                }
            }

            //
            return(_next(context));
        }
Пример #3
0
        public async Task Invoke(HttpContext context)
        {
            if (context.Request.Path.StartsWithSegments(_prefix))
            {
                var script = RequestContextCore.ResolveScript(context.Request);
                if (script.IsValid)
                {
                    var completion = new TaskCompletionSource <RequestCompletionReason>();
                    var phpctx     = new RequestContextCore(context, _rootPath, _options.StringEncoding)
                    {
                        RequestCompletionSource = completion,
                    };

                    //
                    // InvokeAndDispose(phpctx, script);
                    //

                    // run the script, dispose phpctx when finished
                    // using threadpool since we have to be able to end the request and keep script running
                    var task = Task.Run(() => InvokeAndDispose(phpctx, script));

                    // wait for the request to finish,
                    // do not block current thread
                    var timeout = GetRequestTimeoutSeconds(phpctx);
                    if (timeout > 0)
                    {
                        await Task.WhenAny(completion.Task, Task.Delay(timeout * 1000));
                    }
                    else
                    {
                        await completion.Task;
                    }

                    if (task.Exception != null)
                    {
                        // rethrow script exception
                        throw task.Exception;
                    }

                    //
                    return;
                }
            }

            //
            await _next(context);
        }
        public Task Invoke(HttpContext context)
        {
            var script = RequestContextCore.ResolveScript(context.Request);

            if (script.IsValid)
            {
                return(Task.Run(() =>
                {
                    using (var phpctx = new RequestContextCore(context, _rootPath, _options.StringEncoding))
                    {
                        OnContextCreated(phpctx);
                        phpctx.ProcessScript(script);
                    }
                }));
            }

            return(_next(context));
        }
Пример #5
0
        public Task Invoke(HttpContext context)
        {
            var script = RequestContextCore.ResolveScript(context.Request);

            if (script.IsValid)
            {
                using var endevent = new ManualResetEventSlim(false);
                var phpctx = new RequestContextCore(context, _rootPath, _options.StringEncoding)
                {
                    RequestEndEvent = endevent,
                };

                // run the script, dispose phpctx when finished
                var task = Task.Run(() => InvokeAndDispose(phpctx, script));

                // wait for the request to finish
                if (endevent.Wait(GetRequestTimeout(phpctx)) == false)
                {
                    // timeout
                    // context.Response.StatusCode = HttpStatusCode.RequestTimeout;
                }

                phpctx.RequestEndEvent = null;

                if (task.Exception != null)
                {
                    // rethrow script exception
                    throw task.Exception;
                }

                //
                return(Task.CompletedTask);
            }
            else
            {
                return(_next(context));
            }
        }