コード例 #1
0
        private ResolveResult InvokeRouteResolver(Context context, string path, IEnumerable<Tuple<string, decimal>> acceptHeaders)
        {
            context.Request.Headers.Accept = acceptHeaders.ToList();
            context.Request.Url.Path = path;

            return _routeResolver.Resolve(context);
        }
コード例 #2
0
        private ResolveResult Resolve(Context context)
        {
            var originalAcceptHeaders = context.Request.Headers.Accept;
            var originalRequestPath = context.Request.Path;

            return InvokeRouteResolver(context, originalRequestPath, originalAcceptHeaders);
        }
コード例 #3
0
        public async Task<Response> Dispatch(Context context, CancellationToken cancellationToken)
        {
            var resolveResult = Resolve(context);

            context.Parameters = resolveResult.Parameters;
            context.ResolvedRoute = resolveResult.Route;

            return await _routeInvoker.Invoke(resolveResult.Route, cancellationToken, resolveResult.Parameters, context);
        }
コード例 #4
0
        public Response GetContent(Context context)
        {
            foreach (var convention in this.conventions)
            {
                var result = convention.Invoke(context, this.rootPath);

                if (result != null)
                {
                    return result;
                }
            }

            return null;
        }
コード例 #5
0
 public ResponseFormatter Create(Context context)
 {
     return new ResponseFormatter(context, this.serializers);
 }
コード例 #6
-1
ファイル: Engine.cs プロジェクト: gaochundong/Happer
        public async Task<Context> HandleHttp(HttpListenerContext httpContext, Uri baseUri, CancellationToken cancellationToken)
        {
            if (httpContext == null)
                throw new ArgumentNullException("httpContext");

            var request = ConvertRequest(baseUri, httpContext.Request);

            var context = new Context()
            {
                Request = request,
            };

            var staticContentResponse = _staticContentProvider.GetContent(context);
            if (staticContentResponse != null)
            {
                context.Response = staticContentResponse;
            }
            else
            {
                context.Response = await _requestDispatcher.Dispatch(context, cancellationToken).ConfigureAwait(false);
            }

            ConvertResponse(context.Response, httpContext.Response);

            return context;
        }