public void AddHandler(HTTPDelegate HTTPDelegate, String URITemplate = "/", HTTPMethod HTTPMethod = null, HTTPContentType HTTPContentType = null, HTTPAuthentication URIAuthentication = null, HTTPAuthentication HTTPMethodAuthentication = null, HTTPAuthentication ContentTypeAuthentication = null, HTTPDelegate DefaultErrorHandler = null, URIReplacement AllowReplacement = URIReplacement.Fail) { URINode _URINode = null; if (!_URINodes.TryGetValue(URITemplate, out _URINode)) { _URINode = new URINode(URITemplate, URIAuthentication, HTTPDelegate, DefaultErrorHandler); _URINodes.Add(URITemplate, _URINode); } _URINode.AddHandler(HTTPDelegate, HTTPMethod, HTTPContentType, HTTPMethodAuthentication, ContentTypeAuthentication, DefaultErrorHandler, AllowReplacement); }
public void AddHandler(HTTPDelegate HTTPDelegate, HTTPMethod HTTPMethod = null, HTTPContentType HTTPContentType = null, HTTPAuthentication HTTPMethodAuthentication = null, HTTPAuthentication ContentTypeAuthentication = null, HTTPDelegate DefaultErrorHandler = null, URIReplacement AllowReplacement = URIReplacement.Fail) { HTTPMethodNode _HTTPMethodNode = null; if (!_HTTPMethods.TryGetValue(HTTPMethod, out _HTTPMethodNode)) { _HTTPMethodNode = new HTTPMethodNode(HTTPMethod, HTTPMethodAuthentication, HTTPDelegate, DefaultErrorHandler); _HTTPMethods.Add(HTTPMethod, _HTTPMethodNode); } _HTTPMethodNode.AddHandler(HTTPDelegate, HTTPContentType, ContentTypeAuthentication, DefaultErrorHandler, AllowReplacement); }
/// <summary> /// Creates a new HTTP ContentTypeNode. /// </summary> /// <param name="HTTPContentType">The http content type for this service.</param> /// <param name="HTTPContentTypeAuthentication">This and all subordinated nodes demand an explicit HTTP content type authentication.</param> /// <param name="RequestHandler">The default delegate to call for any request to this URI template.</param> /// <param name="DefaultErrorHandler">The default error handling delegate.</param> /// <param name="AllowReplacement">How to handle duplicate URI handlers.</param> internal ContentTypeNode(HTTPContentType HTTPContentType, HTTPAuthentication HTTPContentTypeAuthentication = null, HTTPDelegate RequestHandler = null, HTTPDelegate DefaultErrorHandler = null, URIReplacement AllowReplacement = URIReplacement.Fail) { #region Initial checks if (HTTPContentType == null) throw new ArgumentNullException(nameof(HTTPContentType), "The given HTTP content type must not be null!"); #endregion this.HTTPContentType = HTTPContentType; this.HTTPContentTypeAuthentication = HTTPContentTypeAuthentication; this.RequestHandler = RequestHandler; this.DefaultErrorHandler = DefaultErrorHandler; this.AllowReplacement = AllowReplacement; this.ErrorHandlers = new Dictionary<HTTPStatusCode, HTTPDelegate>(); }
public void AddHandler(HTTPDelegate HTTPDelegate, HTTPContentType HTTPContentType = null, HTTPAuthentication ContentTypeAuthentication = null, HTTPDelegate DefaultErrorHandler = null, URIReplacement AllowReplacement = URIReplacement.Fail) { ContentTypeNode _ContentTypeNode = null; if (HTTPContentType == null) { //RequestHandler = HTTPDelegate; //DefaultErrorHandler = DefaultErrorHandler; } else if (!_HTTPContentTypes.TryGetValue(HTTPContentType, out _ContentTypeNode)) { _ContentTypeNode = new ContentTypeNode(HTTPContentType, ContentTypeAuthentication, HTTPDelegate, DefaultErrorHandler, AllowReplacement); _HTTPContentTypes.Add(HTTPContentType, _ContentTypeNode); } else { if (_ContentTypeNode.AllowReplacement == URIReplacement.Allow) { _ContentTypeNode = new ContentTypeNode(HTTPContentType, ContentTypeAuthentication, HTTPDelegate, DefaultErrorHandler, AllowReplacement); _HTTPContentTypes[HTTPContentType] = _ContentTypeNode; } else if (_ContentTypeNode.AllowReplacement == URIReplacement.Ignore) { } else { throw new ArgumentException("Duplicate HTTP API definition!"); } } }
/// <summary> /// Creates a new HTTP ContentTypeNode. /// </summary> /// <param name="HTTPContentType">The http content type for this service.</param> /// <param name="HTTPContentTypeAuthentication">This and all subordinated nodes demand an explicit HTTP content type authentication.</param> /// <param name="RequestHandler">The default delegate to call for any request to this URI template.</param> /// <param name="DefaultErrorHandler">The default error handling delegate.</param> /// <param name="AllowReplacement">How to handle duplicate URI handlers.</param> internal ContentTypeNode(HTTPContentType HTTPContentType, HTTPAuthentication HTTPContentTypeAuthentication = null, HTTPDelegate RequestHandler = null, HTTPDelegate DefaultErrorHandler = null, URIReplacement AllowReplacement = URIReplacement.Fail) { #region Initial checks if (HTTPContentType == null) { throw new ArgumentNullException(nameof(HTTPContentType), "The given HTTP content type must not be null!"); } #endregion this.HTTPContentType = HTTPContentType; this.HTTPContentTypeAuthentication = HTTPContentTypeAuthentication; this.RequestHandler = RequestHandler; this.DefaultErrorHandler = DefaultErrorHandler; this.AllowReplacement = AllowReplacement; this.ErrorHandlers = new Dictionary <HTTPStatusCode, HTTPDelegate>(); }
// Method Callbacks #region (internal) AddHandler(HTTPDelegate, Hostname = "*", URITemplate = "/", HTTPMethod = null, HTTPContentType = null, HostAuthentication = null, URIAuthentication = null, HTTPMethodAuthentication = null, ContentTypeAuthentication = null, DefaultErrorHandler = null) /// <summary> /// Add a method callback for the given URI template. /// </summary> /// <param name="HTTPDelegate">A delegate called for each incoming HTTP request.</param> /// <param name="Hostname">The HTTP hostname.</param> /// <param name="URITemplate">The URI template.</param> /// <param name="HTTPMethod">The HTTP method.</param> /// <param name="HTTPContentType">The HTTP content type.</param> /// <param name="HostAuthentication">Whether this method needs explicit host authentication or not.</param> /// <param name="URIAuthentication">Whether this method needs explicit uri authentication or not.</param> /// <param name="HTTPMethodAuthentication">Whether this method needs explicit HTTP method authentication or not.</param> /// <param name="ContentTypeAuthentication">Whether this method needs explicit HTTP content type authentication or not.</param> /// <param name="DefaultErrorHandler">The default error handler.</param> internal void AddHandler(HTTPDelegate HTTPDelegate, HTTPHostname Hostname = null, String URITemplate = "/", HTTPMethod HTTPMethod = null, HTTPContentType HTTPContentType = null, HTTPAuthentication HostAuthentication = null, HTTPAuthentication URIAuthentication = null, HTTPAuthentication HTTPMethodAuthentication = null, HTTPAuthentication ContentTypeAuthentication = null, HTTPDelegate DefaultErrorHandler = null, URIReplacement AllowReplacement = URIReplacement.Fail) { lock (Lock) { #region Initial Checks if (HTTPDelegate == null) { throw new ArgumentNullException("HTTPDelegate", "The given parameter must not be null!"); } if (Hostname == null) { Hostname = HTTPHostname.Any; } if (URITemplate.IsNullOrEmpty()) { URITemplate = "/"; } if (HTTPMethod == null && HTTPContentType != null) { throw new ArgumentNullException("If HTTPMethod is null the HTTPContentType must also be null!"); } #endregion #region AddOrUpdate HostNode HostnameNode _HostnameNode = null; if (!_HostnameNodes.TryGetValue(Hostname, out _HostnameNode)) { _HostnameNode = new HostnameNode(Hostname, HostAuthentication, HTTPDelegate, DefaultErrorHandler); _HostnameNodes.Add(Hostname, _HostnameNode); } #endregion _HostnameNode.AddHandler(HTTPDelegate, URITemplate, HTTPMethod, HTTPContentType, URIAuthentication, HTTPMethodAuthentication, ContentTypeAuthentication, DefaultErrorHandler, AllowReplacement); } }
// Method Callbacks #region (internal) AddHandler(HTTPDelegate, Hostname = "*", URITemplate = "/", HTTPMethod = null, HTTPContentType = null, HostAuthentication = null, URIAuthentication = null, HTTPMethodAuthentication = null, ContentTypeAuthentication = null, DefaultErrorHandler = null) /// <summary> /// Add a method callback for the given URI template. /// </summary> /// <param name="HTTPDelegate">A delegate called for each incoming HTTP request.</param> /// <param name="Hostname">The HTTP hostname.</param> /// <param name="URITemplate">The URI template.</param> /// <param name="HTTPMethod">The HTTP method.</param> /// <param name="HTTPContentType">The HTTP content type.</param> /// <param name="HostAuthentication">Whether this method needs explicit host authentication or not.</param> /// <param name="URIAuthentication">Whether this method needs explicit uri authentication or not.</param> /// <param name="HTTPMethodAuthentication">Whether this method needs explicit HTTP method authentication or not.</param> /// <param name="ContentTypeAuthentication">Whether this method needs explicit HTTP content type authentication or not.</param> /// <param name="DefaultErrorHandler">The default error handler.</param> internal void AddHandler(HTTPDelegate HTTPDelegate, HTTPHostname Hostname = null, String URITemplate = "/", HTTPMethod HTTPMethod = null, HTTPContentType HTTPContentType = null, HTTPAuthentication HostAuthentication = null, HTTPAuthentication URIAuthentication = null, HTTPAuthentication HTTPMethodAuthentication = null, HTTPAuthentication ContentTypeAuthentication = null, HTTPDelegate DefaultErrorHandler = null, URIReplacement AllowReplacement = URIReplacement.Fail) { lock (Lock) { #region Initial Checks if (HTTPDelegate == null) throw new ArgumentNullException("HTTPDelegate", "The given parameter must not be null!"); if (Hostname == null) Hostname = HTTPHostname.Any; if (URITemplate.IsNullOrEmpty()) URITemplate = "/"; if (HTTPMethod == null && HTTPContentType != null) throw new ArgumentNullException("If HTTPMethod is null the HTTPContentType must also be null!"); #endregion #region AddOrUpdate HostNode HostnameNode _HostnameNode = null; if (!_HostnameNodes.TryGetValue(Hostname, out _HostnameNode)) { _HostnameNode = new HostnameNode(Hostname, HostAuthentication, HTTPDelegate, DefaultErrorHandler); _HostnameNodes.Add(Hostname, _HostnameNode); } #endregion _HostnameNode.AddHandler(HTTPDelegate, URITemplate, HTTPMethod, HTTPContentType, URIAuthentication, HTTPMethodAuthentication, ContentTypeAuthentication, DefaultErrorHandler, AllowReplacement); } }
public void AddHandler(HTTPDelegate HTTPDelegate, HTTPContentType HTTPContentType = null, HTTPAuthentication ContentTypeAuthentication = null, HTTPDelegate DefaultErrorHandler = null, URIReplacement AllowReplacement = URIReplacement.Fail) { ContentTypeNode _ContentTypeNode = null; if (HTTPContentType == null) { //RequestHandler = HTTPDelegate; //DefaultErrorHandler = DefaultErrorHandler; } else if (!_HTTPContentTypes.TryGetValue(HTTPContentType, out _ContentTypeNode)) { _ContentTypeNode = new ContentTypeNode(HTTPContentType, ContentTypeAuthentication, HTTPDelegate, DefaultErrorHandler, AllowReplacement); _HTTPContentTypes.Add(HTTPContentType, _ContentTypeNode); } else { if (_ContentTypeNode.AllowReplacement == URIReplacement.Allow) { _ContentTypeNode = new ContentTypeNode(HTTPContentType, ContentTypeAuthentication, HTTPDelegate, DefaultErrorHandler, AllowReplacement); _HTTPContentTypes[HTTPContentType] = _ContentTypeNode; } else if (_ContentTypeNode.AllowReplacement == URIReplacement.Ignore) { } else throw new ArgumentException("Duplicate HTTP API definition!"); } }