コード例 #1
0
        public Task ProcessRequest(OwinRequest request)
        {
            byte[] resource = GetResource();

            var response = new OwinResponse(request.Environment)
            {
                ContentType = contentType,
                ContentLength = resource.Length
            };

            return response.WriteAsync(resource);
        }
コード例 #2
0
        public AppFunc DefaultApplication(AppFunc next)
        {
            return env =>
            {
                if (env.Get<string>("OwinDefaultMiddleWare") != "OwinDefaultMiddleWare" || env.Get<string>("Alpha") != "Alpha" || env.Get<string>("Beta") != "Beta")
                {
                    throw new Exception("Test failed to find appropriate custom value added by middleware");
                }

                OwinResponse response = new OwinResponse(env);
                return response.WriteAsync("SUCCESS");
            };
        }
コード例 #3
0
        public Task Invoke(IDictionary<string, object> env)
        {
            var body = Encoding.UTF8.GetBytes("404");

            var response = new OwinResponse(env)
            {
                ReasonPhrase = "",
                StatusCode = 404,
                ContentType = "text/plain;charset=utf-8",
                ContentLength = body.Length
            };

            return response.WriteAsync(body);
        }
コード例 #4
0
        public Task ProcessRequest(OwinRequest request)
        {
            var result = action(GetRequestParams(request));
            var json = JsonConvert.SerializeObject(result);
            var jsonBytes = Encoding.UTF8.GetBytes(json);

            var response = new OwinResponse(request.Environment)
            {
                Headers =
                {
                    {"Cache-Control", new []{"no-store", "no-cache"}},
                    {"Pragma", new []{"no-cache"}}
                },
                ContentType = "application/json;charset=utf-8",
                ContentLength = jsonBytes.Length
            };

            return response.WriteAsync(jsonBytes);
        }
コード例 #5
0
 public Task Invoke(IDictionary<string, object> environment)
 {
     var response = new OwinResponse(environment);
     return response.WriteAsync(this._breadcrumb);
 }
コード例 #6
0
ファイル: Startup.cs プロジェクト: half-ogre/OwinDispatcher
        public void Configuration(IAppBuilder app)
        {
            app.UseDispatcher(dispatcher =>
            {
                // list all the things:
                dispatcher.Get("/things", (environment, next) =>
                {
                    var response = new OwinResponse(environment)
                    {
                        StatusCode = 200,
                        ContentType = "text/plain"
                    };

                    response.Write("# All the things:");
                    response.Write(Environment.NewLine);
                    response.Write(Environment.NewLine);

                    foreach (var thing in _things.Values)
                    {
                        response.Write(String.Concat("- Thing #", thing.Id, ": ", thing.Name));
                        response.Write(Environment.NewLine);
                    }

                    return Task.FromResult((object)null);
                });

                // create a new thing:
                dispatcher.Post("/things", async (environment, next) =>
                {
                    var request = new OwinRequest(environment);
                    var form = await request.ReadFormAsync();

                    var response = new OwinResponse(environment);

                    var thingName = form["name"];

                    if (thingName == null)
                    {
                        response.StatusCode = 400;
                        await response.WriteAsync("The thing to POST is missing a name.");
                        return;
                    }

                    _things.Add(++_lastThingId, new Thing
                    {
                        Id = _lastThingId,
                        Name = thingName
                    });
                    var uri = String.Concat("/things/", _lastThingId);

                    response.StatusCode = 201;
                    response.Headers["Location"] = uri;
                    response.ContentType = "text/plain";
                    await response.WriteAsync(uri);
                });

                // list all the things:
                dispatcher.Get("/things/{id}", (environment, @params, next) =>
                {
                    var response = new OwinResponse(environment);

                    int id;
                    if (!int.TryParse(@params.id, out id))
                    {
                        response.StatusCode = 404;
                        return response.WriteAsync("Not found.");
                    }

                    if (!_things.ContainsKey(id))
                    {
                        response.StatusCode = 404;
                        return response.WriteAsync("Not found.");
                    }

                    var thing = _things[id];

                    response.StatusCode = 200;
                    response.ContentType = "text/plain";

                    return response.WriteAsync(String.Concat("Thing #", thing.Id, " is ", thing.Name, "."));
                });
            });
        }