Пример #1
0
        public RestHints(RestContext ctx)
        {
            var req = ctx.Request;

            Prettyprint = req.Query["$pretty"] != null && (req.Query["$pretty"] == "1" || req.Query["$pretty"].ToLower() == "true");
            Prettyprint |= (Debug.Enabled && req.Native.UserAgent.IsNeitherNullNorEmpty());
            req.Query.Remove("$pretty");

            jQueryCacheBypass = req.Query["_"];
            req.Query.Remove("_");
        }
Пример #2
0
        public RestHints(RestContext ctx)
        {
            var req = ctx.Request;

            Prettyprint  = req.Query["$pretty"] != null && (req.Query["$pretty"] == "1" || req.Query["$pretty"].ToLower() == "true");
            Prettyprint |= (Debug.Enabled && req.Native.UserAgent.IsNeitherNullNorEmpty());
            req.Query.Remove("$pretty");

            jQueryCacheBypass = req.Query["_"];
            req.Query.Remove("_");
        }
Пример #3
0
        public void ProcessRequest(HttpContext ctx)
        {
            var rctx = new RestContext(ctx);
            var req = rctx.Request;
            var resp = rctx.Response;

            try
            {
                Info.EnsureBlankLine();
                Info.WriteLine("Received {0} request to {1}", req.Method, req.Resource);
                Info.WriteLine("    * Query: {0}", req.Query.Select(kvp => String.Format("{0} = {1}", kvp.Key, (String)kvp.Value)).StringJoin().Fluent(s => s.IsEmpty() ? "<empty>" : s));
                Info.WriteLine("    * Data: {0}", ((Json)req.Data).ToCompactString().Fluent(s => s.IsEmpty() ? "<empty>" : s));

                try
                {
                    var result = req.Dispatch();
                    if (result.Result == DispatchResult.Success)
                    {
                        result.Handler();
                    }
                    else
                    {
                        var statusCode = result.Result == DispatchResult.UrlMismatch ? HttpStatusCode.NotFound :
                            result.Result == DispatchResult.ArgsMismatch ? HttpStatusCode.NotAcceptable :
                            result.Result == DispatchResult.MethodNotAllowed ? HttpStatusCode.MethodNotAllowed :
                            result.Result == DispatchResult.NotAuthenticated ? HttpStatusCode.Unauthorized :
                            result.Result == DispatchResult.NotAuthorized ? HttpStatusCode.Forbidden :
                            result.Result == DispatchResult.Ambiguous ? HttpStatusCode.Ambiguous :
                            ((Func<HttpStatusCode>)(() => { throw AssertionHelper.Fail(); }))();
                        resp.Fail(statusCode);
                    }
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    Error.EnsureBlankLine();
                    Error.WriteLine(CallStack.Enabled ? ex.ToString() : ex.Message);
                    resp.Fail(ex);
                }
            }
            catch (Exception)
            {
                resp.Fail("A fatal error has occurred");
            }
        }
Пример #4
0
 public RestRequest(RestContext ctx)
 {
     _ctx = ctx.AssertNotNull(); Url = new Url(Native.Url);
 }
Пример #5
0
 public RestResponse(RestContext ctx)
 {
     _ctx = ctx.AssertNotNull();
 }
Пример #6
0
 public RestRequest(RestContext ctx)
 {
     _ctx = ctx.AssertNotNull(); Url = new Url(Native.Url);
 }
Пример #7
0
 public RestResponse(RestContext ctx)
 {
     _ctx = ctx.AssertNotNull();
 }