Esempio n. 1
0
        public ApiRequestObject(ApiRequest request)
        {
            Verb       = request.Verb;
            ActionName = request.ActionName;
            Arguments  = request.ActionArguments;
            Headers    = request.Headers;
            Data       = request.Data;

            Respond = delegate(object data, Dictionary <string, object> options) {
                options = Script.Or(options, new Dictionary <string, object>());

                HttpStatusCode statusCode = Script.Or((HttpStatusCode)options["statusCode"],
                                                      (data == null) ? HttpStatusCode.NoContent : HttpStatusCode.OK);

                ServerResponse response = new ServerResponse(statusCode);

                if (data != null)
                {
                    if (data is string)
                    {
                        response.AddTextContent((string)data, Script.Or((string)options["contentType"], "text/plain"));
                    }
                    else
                    {
                        response.AddObjectContent(data);
                    }
                }

                return(Deferred.Create <ServerResponse>(response).Task);
            };
        }