public Task Invoke(IDictionary <string, object> arg)
        {
            var env       = new OwinEnvironment(arg);
            var pathMatch = pathPattern.Match(env.Request.Path);

            if (pathMatch.Success)
            {
                if (env.TryGetValue(OwinEnvironment.Owin.RequestMethod, out string method) && methods.Contains(method))
                {
                    env.Response.StatusCode = System.Net.HttpStatusCode.OK;
                    env.Environment[OwinEnvironment.Owin.RequestPathMatch] = pathMatch;
                    var pathBase = env.Get(OwinEnvironment.Owin.RequestPathBase, "");
                    env.Environment[OwinEnvironment.Owin.RequestPathBase] = pathBase + pathMatch.Value;
                    env.Environment[OwinEnvironment.Owin.RequestPath]     = env.Request.Path.Substring(pathMatch.Length);
                    env.RemoveResponseHeader("Allow");
                    return(branch.Invoke(arg));
                }
                else
                {
                    env.Response.StatusCode = System.Net.HttpStatusCode.MethodNotAllowed;
                    var allow = env.GetResponseHeader("Allow", (string)null);
                    if (allow == null)
                    {
                        allow = String.Join(", ", methods);
                    }
                    else
                    {
                        allow = String.Join(", ", Enumerable.Repeat(allow, 1).Concat(methods));
                    }
                    env.SetResponseHeader("Allow", allow);
                }
            }
            return(nextApp.Invoke(arg));
        }
Example #2
0
 internal OwinRequest(OwinEnvironment owner)
 {
     env     = owner;
     Headers = new RequestHeaders(env);
     Query   = new RequestQuery(env);
     Cookies = new RequestCookies(env);
     Body    = env.Get <System.IO.Stream>(Owin.RequestBody);
 }
Example #3
0
            public Task WriteAsync(byte[] bytes, CancellationToken ct)
            {
                var strm = env.Get <System.IO.Stream>(Owin.ResponseBody);

                return(strm.WriteAsync(bytes, 0, bytes.Length, ct));
            }