protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, System.Threading.CancellationToken cancellationToken ) { var endpoint = this.configuration.GetEndpoint<JasonWebAPIEndpoint>(); var isJasonExecute = request.Method == HttpMethod.Post && request.RequestUri.AbsolutePath.IndexOf( "api/jason", StringComparison.OrdinalIgnoreCase ) != -1; if( isJasonExecute ) { var args = new JasonRequestArgs(); args.IsJasonExecute = isJasonExecute; args.IsCommandInterceptor = false; args.HttpRequest = request; var scope = this.httpConfiguration.DependencyResolver.BeginScope(); if( request.Headers.Contains( this.correlationIdHeader ) ) { args.CorrelationId = request.Headers.GetValues( this.correlationIdHeader ).Single(); args.AppendCorrelationIdToResponse = true; } if( endpoint.OnJasonRequest != null ) { endpoint.OnJasonRequest( args ); } var command = Extract( request.Content, typeof( Object ) ); var result = this.defaultExecutor( args.HttpRequest, command ); var task = Task.FromResult( result ) .ContinueWith( t => { try { if( !t.IsFaulted && args.AppendCorrelationIdToResponse && !String.IsNullOrWhiteSpace( args.CorrelationId ) ) { t.Result.Headers.Add( this.correlationIdHeader, args.CorrelationId ); } return t; } finally { scope.Dispose(); } } ) .Unwrap(); return task; } return base.SendAsync( request, cancellationToken ); }
protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { var endpoint = this.configuration.GetEndpoint <JasonWebAPIEndpoint>(); var isJasonExecute = request.Method == HttpMethod.Post && request.RequestUri.AbsolutePath.IndexOf("api/jason", StringComparison.OrdinalIgnoreCase) != -1; if (isJasonExecute) { var args = new JasonRequestArgs(); args.IsJasonExecute = isJasonExecute; args.IsCommandInterceptor = false; args.HttpRequest = request; var scope = this.httpConfiguration.DependencyResolver.BeginScope(); if (request.Headers.Contains(this.correlationIdHeader)) { args.CorrelationId = request.Headers.GetValues(this.correlationIdHeader).Single(); args.AppendCorrelationIdToResponse = true; } if (endpoint.OnJasonRequest != null) { endpoint.OnJasonRequest(args); } var command = Extract(request.Content, typeof(Object)); var result = this.defaultExecutor(args.HttpRequest, command); var task = Task.FromResult(result) .ContinueWith(t => { try { if (!t.IsFaulted && args.AppendCorrelationIdToResponse && !String.IsNullOrWhiteSpace(args.CorrelationId)) { t.Result.Headers.Add(this.correlationIdHeader, args.CorrelationId); } return(t); } finally { scope.Dispose(); } }) .Unwrap(); return(task); } return(base.SendAsync(request, cancellationToken)); }