コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpListenerReceiver"/> class.
        /// </summary>
        /// <param name="name">The name of the receiver.</param>
        /// <param name="prefixes">
        /// The URI prefixes handled by the <see cref="HttpListener"/>. See
        /// https://docs.microsoft.com/en-us/dotnet/api/system.net.httplistener for
        /// more information.
        /// </param>
        /// <param name="path">
        /// The path that requests must match in order to be handled. Any request whose
        /// path does not match this value will receive a 404 Not Found response.
        /// </param>
        /// <param name="httpResponseGenerator">
        /// An object that determines the http response that is returned to clients,
        /// depending on whether the message is acknowledged, rejected, or rolled back.
        /// </param>
        /// <param name="method">
        /// The http method that requests must have in order to be handled. Any request
        /// that does not have this method will receive a 405 Method Not Allowed response.
        /// </param>
        /// <param name="requiredHeaders">
        /// The HTTP headers that incoming requests are required to match in order to be handled.
        /// Any request that does not have match the required headers will receive a 4xx response.
        /// </param>
        public HttpListenerReceiver(string name, IReadOnlyList <string> prefixes, string path,
                                    IHttpResponseGenerator httpResponseGenerator, string method = DefaultMethod, RequiredHttpRequestHeaders requiredHeaders = null)
            : base(name)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            Prefixes = prefixes ?? throw new ArgumentNullException(nameof(prefixes));
            foreach (var prefix in Prefixes)
            {
                _listener.Prefixes.Add(prefix);
            }

            Path = path.Trim('/');
            var pathTokens  = new List <string>();
            var pathPattern = "^/?" + Regex.Replace(Path ?? "", "{([^}]+)}", m =>
            {
                var token = m.Groups[1].Value;
                pathTokens.Add(token);
                return($"(?<{token}>[^/]+)");
            }) + "/?$";

            _pathRegex  = new Regex(pathPattern, RegexOptions.IgnoreCase);
            _pathTokens = pathTokens;

            HttpResponseGenerator = httpResponseGenerator ?? throw new ArgumentNullException(nameof(httpResponseGenerator));
            Method          = method ?? throw new ArgumentNullException(nameof(method));
            RequiredHeaders = requiredHeaders;
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpListenerReceiver"/> class.
 /// </summary>
 /// <param name="name">The name of the receiver.</param>
 /// <param name="prefixes">
 /// The URI prefixes handled by the <see cref="HttpListener"/>. See
 /// https://docs.microsoft.com/en-us/dotnet/api/system.net.httplistener for
 /// more information.
 /// </param>
 /// <param name="path">
 /// The path that requests must match in order to be handled. Any request whose
 /// path does not match this value will receive a 404 Not Found response.
 /// </param>
 /// <param name="acknowledgeStatusCode">
 /// The status code to be returned to the client when a message is acknowledged.
 /// </param>
 /// <param name="rollbackStatusCode">
 /// The status code to be returned to the client when a message is rolled back.
 /// </param>
 /// <param name="rejectStatusCode">
 /// The status code to be returned to the client when a message is acknowledged.
 /// </param>
 /// <param name="method">
 /// The http method that requests must have in order to be handled. Any request
 /// that does not have this method will receive a 405 Method Not Allowed response.
 /// </param>
 /// <param name="requiredHeaders">
 /// The HTTP headers that incoming requests are required to match in order to be handled.
 /// Any request that does not have match the required headers will receive a 4xx response.
 /// </param>
 public HttpListenerReceiver(string name, IReadOnlyList <string> prefixes, string path,
                             int acknowledgeStatusCode = DefaultAcknowledgeStatusCode,
                             int rollbackStatusCode    = DefaultRollbackStatusCode,
                             int rejectStatusCode      = DefaultRejectStatusCode,
                             string method             = DefaultMethod, RequiredHttpRequestHeaders requiredHeaders = null)
     : this(name, prefixes, path,
            new DefaultHttpResponseGenerator(acknowledgeStatusCode, rollbackStatusCode, rejectStatusCode),
            method, requiredHeaders)
 {
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpListenerReceiver"/> class.
 /// </summary>
 /// <param name="name">The name of the receiver.</param>
 /// <param name="url">
 /// The url that the <see cref="HttpListener"/> should listen to. See
 /// https://docs.microsoft.com/en-us/dotnet/api/system.net.httplistener for
 /// more information.
 /// </param>
 /// <param name="httpResponseGenerator">
 /// An object that determines the http response that is returned to clients,
 /// depending on whether the message is acknowledged, rejected, or rolled back.
 /// </param>
 /// <param name="method">
 /// The http method that requests must have in order to be handled. Any request
 /// that does not have this method will receive a 405 Method Not Allowed response.
 /// </param>
 /// <param name="requiredHeaders">
 /// The HTTP headers that incoming requests are required to match in order to be handled.
 /// Any request that does not have match the required headers will receive a 4xx response.
 /// </param>
 public HttpListenerReceiver(string name, string url,
                             IHttpResponseGenerator httpResponseGenerator, string method = DefaultMethod, RequiredHttpRequestHeaders requiredHeaders = null)
     : this(name, GetPrefixes(url), GetPath(url), httpResponseGenerator, method, requiredHeaders)
 {
 }