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); }
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; }
// 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; }
public virtual IObservable<Unit> Route(IKayakContext context) { context.GetInvocationInfo().Method = RouteFunc(context); return null; }
public virtual IObservable<Unit> Handle(IKayakContext context) { return context.HandleWithCoroutine(HandleInvocation) ?? HandleInvocation(context); }
public virtual IObservable<Unit> Bind(IKayakContext context) { context.DeserializeArgsFromHeaders(); return context.DeserializeArgsFromJson(JsonMapper); }
public virtual IObservable<bool> Authenticate(IKayakContext context) { return null; }