コード例 #1
0
        public virtual IObservable<Unit> HandleInvocation(IKayakContext context)
        {
            var info = context.GetInvocationInfo();

            if (info.Exception == null && info.Result == null) return null;

            return context.ServeFile() ?? context.SerializeResultToJson(JsonMapper);
        }
コード例 #2
0
        public MethodInfo GetMethodForContext(IKayakContext context)
        {
            var request = context.Request;

            MethodMatch match = GetBestMatch(request.Path.TrimEnd('/').Split('/'), request.Verb);

            if (match == null)
                return typeof(DefaultResponses).GetMethod("NotFound");

            if (match.Method == null)
                return typeof(DefaultResponses).GetMethod("InvalidMethod");

            context.Items[PathParamsContextKey] = match.Params;

            return match.Method;
        }
コード例 #3
0
        // wish i had an evented JSON parser.
        static IEnumerable<object> BufferRequestBody(IKayakContext context)
        {
            var bytesRead = 0;
            var contentLength = context.Request.Headers.GetContentLength();
            var result = new List<ArraySegment<byte>>();

            while (true)
            {
                ArraySegment<byte> data = default(ArraySegment<byte>);
                yield return context.Request.Read().Do(d => data = d);

                result.Add(data);

                bytesRead += data.Count;

                if (bytesRead == contentLength)
                    break;
            }

            yield return result;
        }
コード例 #4
0
 public virtual IObservable<Unit> Route(IKayakContext context)
 {
     context.GetInvocationInfo().Method = RouteFunc(context);
     return null;
 }
コード例 #5
0
 public virtual IObservable<Unit> Handle(IKayakContext context)
 {
     return context.HandleWithCoroutine(HandleInvocation) ?? HandleInvocation(context);
 }
コード例 #6
0
 public virtual IObservable<Unit> Bind(IKayakContext context)
 {
     context.DeserializeArgsFromHeaders();
     return context.DeserializeArgsFromJson(JsonMapper);
 }
コード例 #7
0
 public virtual IObservable<bool> Authenticate(IKayakContext context)
 {
     return null;
 }