/// <summary>Initializes a new instance of the <see cref="UrsaHandler"/> class.</summary> /// <param name="next">Next middleware in the pipeline.</param> /// <param name="requestHandler">The request handler.</param> public UrsaHandler(OwinMiddleware next, IRequestHandler<RequestInfo, ResponseInfo> requestHandler) : base(next) { if (requestHandler == null) { throw new ArgumentNullException("requestHandler"); } _requestHandler = requestHandler; }
public RequestProcTimeMiddleware(OwinMiddleware next, RequestProcTimeOption requestProcTimeOption = null) : base(next) { _next = next; //第一个参数是固定的,后边还可以添加自定义的其它参数 _requestProcTimeOption = requestProcTimeOption; }
public PassThroughMiddleware(OwinMiddleware next, string p1, int p2, object p3) : base(next) { this.p1 = p1; this.p2 = p2; this.p3 = p3; }
public ConsulateMiddleware(OwinMiddleware next, Uri consulBase) : base(next) { _consulBase = consulBase; _consulClient = new HttpClient(new TracingHandler(new HttpClientHandler())) { BaseAddress = consulBase }; }
/// <summary> /// Initializes a new instance of the <see cref="ThrottlingMiddleware"/> class. /// By default, the <see cref="QuotaExceededResponseCode"/> property /// is set to 429 (Too Many Requests). /// </summary> public ThrottlingMiddleware(OwinMiddleware next) : base(next) { QuotaExceededResponseCode = (HttpStatusCode)429; Repository = new CacheRepository(); core = new ThrottlingCore(); }
public RequestLogMiddleware(OwinMiddleware next, Action<string> requestLogProceAction) : base(next) { _next = next; //第一个参数是固定的,后边还可以添加自定义的其它参数 _requestLogProceAction = requestLogProceAction; }
public RequestTrackingMiddleware(OwinMiddleware next, TelemetryConfiguration telemetryConfiguration) : base(next) { _telemetryClient = telemetryConfiguration == null ? new TelemetryClient() : new TelemetryClient(telemetryConfiguration); }
public KittenStatusCodeMiddleware(OwinMiddleware next, KittenStatusCodeOptions options) : base(next) { this.options = options; links = new Dictionary<int, string>(); GenerateLinks(); }
public ForceSslWhenAuthenticatedMiddleware(OwinMiddleware next, IAppBuilder app, string cookieName, int sslPort) : base(next) { CookieName = cookieName; SslPort = sslPort; _logger = app.CreateLogger<ForceSslWhenAuthenticatedMiddleware>(); }
public RequestLogMiddleware(OwinMiddleware next, RequestLogOption requestLogOption) : base(next) { _next = next; //第一个参数是固定的,后边还可以添加自定义的其它参数 _requestLogOption = requestLogOption; }
/// <summary> /// Initializes a new instance of the <see cref="ThrottlingMiddleware"/> class. /// Persists the policy object in cache using <see cref="IPolicyRepository"/> implementation. /// The policy object can be updated by <see cref="ThrottleManager"/> at runtime. /// </summary> /// <param name="policy"> /// The policy. /// </param> /// <param name="policyRepository"> /// The policy repository. /// </param> /// <param name="repository"> /// The repository. /// </param> /// <param name="logger"> /// The logger. /// </param> /// <param name="ipAddressParser"> /// The IpAddressParser /// </param> public ThrottlingMiddleware(OwinMiddleware next, ThrottlePolicy policy, IPolicyRepository policyRepository, IThrottleRepository repository, IThrottleLogger logger, IIpAddressParser ipAddressParser) : base(next) { core = new ThrottlingCore(); core.Repository = repository; Repository = repository; Logger = logger; if (ipAddressParser != null) { core.IpAddressParser = ipAddressParser; } QuotaExceededResponseCode = (HttpStatusCode)429; this.policy = policy; this.policyRepository = policyRepository; if (policyRepository != null) { policyRepository.Save(ThrottleManager.GetPolicyKey(), policy); } }
public void Init() { _fixture = new Fixture().Customize(new AutoRhinoMockCustomization()); _nextMiddleware = MockRepository.GenerateMock<OwinMiddleware>(new FakeRootMiddelware()); _handlerPool = new ThermometerRouteHandlerPool(); _sut = new QuestionRouteMiddleware(_nextMiddleware, _handlerPool); }
public ResourceMiddleware(OwinMiddleware next) : base(next) { resourceWebRequestFactory = new ResourceWebRequestFactory(); resourceWebRequestFactory.PluginAliasMap = base.pluginAliasDict; resourceWebRequestFactory.AssemblyMap = new Dictionary<String, Assembly>(); //注册resource:前缀URI处理程序 WebRequest.RegisterPrefix("resource:", resourceWebRequestFactory); }
public PersistentConnectionMiddleware(OwinMiddleware next, Type connectionType, ConnectionConfiguration configuration) : base(next) { _connectionType = connectionType; _configuration = configuration; }
/// <summary> /// Constructor /// </summary> /// <param name="next">The next piece of OWIN middleware to invoke</param> /// <param name="httpCorrelationHeaderKey">The name of the header to use for the correlation ID</param> public HttpCorrelator(OwinMiddleware next, string httpCorrelationHeaderKey) : base(next) { _httpCorrelationHeaderKey = httpCorrelationHeaderKey; if (string.IsNullOrWhiteSpace(httpCorrelationHeaderKey)) { throw new ArgumentException("A correlation header name must be provided", nameof(httpCorrelationHeaderKey)); } }
/// <summary>Initializes a new instance of the <see cref="SwaggerMiddleware"/> class.</summary> /// <param name="next">The next middleware.</param> /// <param name="path">The path.</param> /// <param name="controllerTypes">The controller types.</param> /// <param name="settings">The settings.</param> /// <param name="schemaGenerator">The schema generator.</param> public SwaggerMiddleware(OwinMiddleware next, string path, IEnumerable<Type> controllerTypes, SwaggerOwinSettings settings, SwaggerJsonSchemaGenerator schemaGenerator) : base(next) { _path = path; _controllerTypes = controllerTypes; _settings = settings; _schemaGenerator = schemaGenerator; }
/// <summary> /// Creates the GenkanMiddleware to use with owin. /// </summary> /// <param name="next">The next middleware to call after Genkan.</param> /// <param name="tobira">The <see cref="ITobira"/> to forward the call to.</param> /// <param name="requestResponseFactory">The <see cref="IRequestResponseFactory"/> to create the request and response.</param> public GenkanMiddleware(OwinMiddleware next, ITobira tobira, IRequestResponseFactory requestResponseFactory) : base(next) { if (tobira == null) throw new ArgumentNullException(nameof(tobira)); if (requestResponseFactory == null) throw new ArgumentNullException(nameof(requestResponseFactory)); _requestResponseFactory = requestResponseFactory; _tobira = tobira; }
public SaasKitOwinAdapter(OwinMiddleware next, ISaasKitEngine engine) : base(next) { if (engine == null) { throw new ArgumentNullException("engine"); } this.engine = engine; }
public IsPrivateFolderMiddleware(OwinMiddleware next, WebserverOptions options) : base(next) { if (options == null) { throw new ArgumentNullException("options"); } _options = options; }
public ClaimsTransformationMiddleware(OwinMiddleware next, ClaimsAuthenticationManager claimsAuthenticationManager) : base(next) { if (claimsAuthenticationManager == null) { throw new ArgumentNullException("claimsAuthenticationManager"); } _claimsAuthenticationManager = claimsAuthenticationManager; }
public ResourceExistMiddleware(OwinMiddleware next, WebserverOptions options) : base(next) { if (options == null) { throw new ArgumentNullException("options"); } _options = options; }
public TeapotMiddleware(OwinMiddleware next, TeapotOptions options) : base(next) { if (options == null) { throw new ArgumentNullException("options"); } this.options = options; }
public JwtTokenIssuerMiddleware(OwinMiddleware next, JwtTokenIssuerOptions options) : base(next) { if (options == null) throw new ArgumentNullException("options"); ValidateOptions(options); _options = options; }
public IpAuthenticationMiddleware(OwinMiddleware next) : base(next) { _nextMiddleware = next; _dbContext = new ApplicationDbContext(); _allowedIPs = new List<string>() { {"127.0.0.1"} }; }
public GitReceivePackMiddleware(OwinMiddleware next, WebserverOptions options) : base(next) { if (options == null) { throw new ArgumentNullException("options"); } _options = options; }
public AntiforgeryMiddleware(OwinMiddleware next, AntiforgeryOptions options) : base(next) { if (options == null) { throw new ArgumentNullException("options"); } _options = options; }
public void Init() { _fixture = new Fixture().Customize(new AutoRhinoMockCustomization()); _nextMiddleware = MockRepository.GenerateMock<OwinMiddleware>(new FakeRootMiddelware()); _handlerPool = new ThermometerRouteHandlerPool(); _handlerPool.Add(new ThermometerHandler(new ThermometerQuestion("/abc", "def"), req => new {result = "ghi"})); _sut = new ListAllQuestionMiddleware(_nextMiddleware, _handlerPool); }
public CommandPublishMiddleware( OwinMiddleware next, ILog log, IJsonSerializer jsonSerializer, ISerializedCommandPublisher serializedCommandPublisher) : base(next) { _log = log; _jsonSerializer = jsonSerializer; _serializedCommandPublisher = serializedCommandPublisher; }
/// <summary> /// Initialize a new instance of the <see cref="HttpTrackingMiddleware"/> class. /// </summary> /// <param name="next">A reference to the next OwinMiddleware object in the chain.</param> /// <param name="options">A reference to an <see cref="HttpTrackingOptions"/> class.</param> public HttpTrackingMiddleware(OwinMiddleware next, HttpTrackingOptions options) : base(next) { storage_ = options.TrackingStore; if (!string.IsNullOrEmpty(options.TrackingIdPropertyName)) trackingIdPropertyName_ = options.TrackingIdPropertyName; maxRequestLength_ = options.MaximumRecordedRequestLength ?? maxRequestLength_; maxResponseLength_ = options.MaximumRecordedResponseLength ?? maxResponseLength_; }
/// <summary> /// Initialize a new instance of the <see cref="HttpLogging"/> class. /// </summary> /// <param name="next">A reference to the next OwinMiddleware object in the chain.</param> /// <param name="options">A reference to an <see cref="HttpLoggingOptions"/> class.</param> public HttpLogging(OwinMiddleware next, HttpLoggingOptions options) : base(next) { HttpLoggingStore = options.TrackingStore; if (!string.IsNullOrEmpty(options.TrackingIdPropertyName)) _trackingIdPropertyName = options.TrackingIdPropertyName; _maxRequestLength = options.MaximumRecordedRequestLength ?? _maxRequestLength; _maxResponseLength = options.MaximumRecordedResponseLength ?? _maxResponseLength; }
/// <summary> /// Instantiates the base query middleware with an optional pointer to /// the next component. /// </summary> /// <param name="next"> /// An optional pointer to the next component. /// </param> /// <param name="queryExecutor"> /// A required query executor resolver. /// </param> /// <param name="resultSerializer"> /// </param> /// <param name="options"> /// </param> protected QueryMiddlewareBase( RequestDelegate next, IQueryExecutor queryExecutor, IQueryResultSerializer resultSerializer, QueryMiddlewareOptions options) #if ASPNETCLASSIC : base(next) #endif { #if !ASPNETCLASSIC Next = next; #endif Executor = queryExecutor ?? throw new ArgumentNullException(nameof(queryExecutor)); _resultSerializer = resultSerializer ?? throw new ArgumentNullException(nameof(resultSerializer)); Options = options ?? throw new ArgumentNullException(nameof(options)); if (Options.Path.Value.Length > 1) { var path1 = new PathString(options.Path.Value.TrimEnd('/')); PathString path2 = path1.Add(new PathString("/")); _isPathValid = ctx => ctx.IsValidPath(path1, path2); } else { _isPathValid = ctx => ctx.IsValidPath(options.Path); } #if ASPNETCLASSIC _accessor = queryExecutor.Schema.Services .GetService<IOwinContextAccessor>() as OwinContextAccessor; #endif }
public GlobalExceptionMiddlewareUnitTest(Microsoft.Owin.OwinMiddleware next) : base(next) { }
/// <summary> /// Instantiates the middleware with an optional pointer to the next component. /// </summary> /// <param name="next"></param> protected OwinMiddleware(OwinMiddleware next) { Next = next; }
public LoggingMiddleware(Microsoft.Owin.OwinMiddleware next) : base(next) { }
public OpenIdConnectAuthenticationPatchedMiddleware(Microsoft.Owin.OwinMiddleware next, Owin.IAppBuilder app, Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions options) : base(next, app, options) { this._logger = Microsoft.Owin.Logging.AppBuilderLoggerExtensions.CreateLogger <OpenIdConnectAuthenticationPatchedMiddleware>(app); }
private async Task InvokeInternal(IContext ctx) { #if !USE_ASPNETCORE if (ctx.Get <bool>("gotoNext")) { await Next?.Invoke(ctx); return; } #else #endif var request = await _requestMapper.MapAsync(ctx.Request, _options); bool logRequest = false; ResponseMessage response = null; MappingMatcherResult result = null; try { foreach (var mapping in _options.Mappings.Values.Where(m => m?.Scenario != null)) { // Set start if (!_options.Scenarios.ContainsKey(mapping.Scenario) && mapping.IsStartState) { _options.Scenarios.TryAdd(mapping.Scenario, new ScenarioState { Name = mapping.Scenario }); } } result = _mappingMatcher.FindBestMatch(request); var targetMapping = result?.Mapping; if (targetMapping == null) { logRequest = true; _options.Logger.Warn("HttpStatusCode set to 404 : No matching mapping found"); response = ResponseMessageBuilder.Create("No matching mapping found", 404); return; } logRequest = targetMapping.LogMapping; if (targetMapping.IsAdminInterface && _options.AuthorizationMatcher != null) { bool present = request.Headers.TryGetValue(HttpKnownHeaderNames.Authorization, out WireMockList <string> authorization); if (!present || _options.AuthorizationMatcher.IsMatch(authorization.ToString()) < MatchScores.Perfect) { _options.Logger.Error("HttpStatusCode set to 401"); response = ResponseMessageBuilder.Create(null, 401); return; } } if (!targetMapping.IsAdminInterface && _options.RequestProcessingDelay > TimeSpan.Zero) { await Task.Delay(_options.RequestProcessingDelay.Value); } response = await targetMapping.ProvideResponseAsync(request); if (targetMapping.Scenario != null) { _options.Scenarios[targetMapping.Scenario].NextState = targetMapping.NextState; _options.Scenarios[targetMapping.Scenario].Started = true; _options.Scenarios[targetMapping.Scenario].Finished = targetMapping.NextState == null; } } catch (Exception ex) { _options.Logger.Error($"Providing a Response for Mapping '{result?.Mapping?.Guid}' failed. HttpStatusCode set to 500. Exception: {ex}"); response = ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500); } finally { var log = new LogEntry { Guid = Guid.NewGuid(), RequestMessage = request, ResponseMessage = response, MappingGuid = result?.Mapping?.Guid, MappingTitle = result?.Mapping?.Title, RequestMatchResult = result?.RequestMatchResult }; LogRequest(log, logRequest); await _responseMapper.MapAsync(response, ctx.Response); } await CompletedTask; }