| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using CoreWCF.Channels.Framing; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Configuration |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Represents a middleware that maps a request path to a sub-request pipeline. |
| | | 12 | | /// </summary> |
| | | 13 | | public class MapMiddleware |
| | | 14 | | { |
| | | 15 | | private readonly HandshakeDelegate _next; |
| | | 16 | | private readonly MapOptions _options; |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Creates a new instance of <see cref="MapMiddleware"/>. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="next">The delegate representing the next middleware in the request pipeline.</param> |
| | | 22 | | /// <param name="options">The middleware options.</param> |
| | 166 | 23 | | public MapMiddleware(HandshakeDelegate next, MapOptions options) |
| | | 24 | | { |
| | 166 | 25 | | _next = next ?? throw new ArgumentNullException(nameof(next)); |
| | 166 | 26 | | _options = options ?? throw new ArgumentNullException(nameof(options)); |
| | 166 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Executes the middleware. |
| | | 31 | | /// </summary> |
| | | 32 | | /// <param name="context">The <see cref="HttpContext"/> for the current request.</param> |
| | | 33 | | /// <returns>A task that represents the execution of this middleware.</returns> |
| | | 34 | | public async Task Invoke(FramingConnection connection) |
| | | 35 | | { |
| | 165 | 36 | | if (connection == null) |
| | | 37 | | { |
| | 0 | 38 | | throw new ArgumentNullException(nameof(connection)); |
| | | 39 | | } |
| | | 40 | | |
| | 165 | 41 | | if (_options.Predicate(connection)) |
| | | 42 | | { |
| | 115 | 43 | | await _options.Branch(connection); |
| | | 44 | | } |
| | | 45 | | else |
| | | 46 | | { |
| | 50 | 47 | | await _next(connection); |
| | | 48 | | } |
| | 164 | 49 | | } |
| | | 50 | | } |
| | | 51 | | } |