Exemplo n.º 1
0
 /// <summary>
 /// Create a new HTTP service instance.
 /// </summary>
 /// <param name="localaddr"></param>
 /// <param name="port"></param>
 public HttpServer(HandleRequestDelegate callback)
 {
     _localaddr   = IPAddress.Any;
     _port        = 80;
     _listener    = null;
     _started     = false;
     _connections = new List <HttpConnection>();
     _callback    = callback;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a route handler for the specified route and HTTP methods, using a delegate.
 /// <para>
 /// This is useful for quick, one-off serving of pages. For more complex cases, such as
 /// serving files from the file system, it is recommended to use the slightly more complex
 /// <see cref="IHTTPRouteHandler"/> interface.
 /// </para>
 /// </summary>
 /// <param name="route">The route, for example "/hello_world"</param>
 /// <param name="methods">
 /// The HTTP Methods to support. HTTPMethod has the <c>[Flag]</c> metadata,
 /// which makes it possible to support multiple methods in a single page.
 /// </param>
 /// <param name="handlerMethod">A method delegate. See <see cref="HandleRequestDelegate"/> for usage.</param>
 public RouteMapper Add(string route, HTTPMethod methods, HandleRequestDelegate handlerMethod, bool acceptSubroutes = false)
 {
     lock (_lock)
     {
         RouteHandlerDelegate newHandler = new RouteHandlerDelegate(handlerMethod, acceptSubroutes);
         RouteMapper          mapper     = new RouteMapper(route, methods, newHandler);
         _routes.Add(mapper);
         return(mapper);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Adds a route handler for the specified route and HTTP methods, using a delegate.
 /// <para>
 /// This is useful for quick, one-off serving of pages. For more complex cases, such as
 /// serving files from the file system, it is recommended to use the slightly more complex
 /// <see cref="IHTTPRouteHandler"/> interface.
 /// </para>
 /// </summary>
 /// <param name="route">The route, for example "/hello_world"</param>
 /// <param name="methods">
 /// The HTTP Methods to support. HTTPMethod has the <c>[Flag]</c> metadata,
 /// which makes it possible to support multiple methods in a single page.
 /// </param>
 /// <param name="handlerMethod">A method delegate. See <see cref="HandleRequestDelegate"/> for usage.</param>
 public RouteMapper Add(string route, HTTPMethod methods, HandleRequestDelegate handlerMethod, bool acceptSubroutes = false)
 {
     lock (_lock)
     {
         RouteHandlerDelegate newHandler = new RouteHandlerDelegate(handlerMethod, acceptSubroutes);
         RouteMapper mapper = new RouteMapper(route, methods, newHandler);
         _routes.Add(mapper);
         return mapper;
     }
 }
Exemplo n.º 4
0
 public void HandleRequests(HandleRequestDelegate handler)
 {
     this.requestHandlerMethod = handler;
 }
Exemplo n.º 5
0
 public RouteHandlerDelegate(HandleRequestDelegate requestDelegate, bool acceptSubroutes = false, bool acceptWebsockets = false)
 {
     _delegate        = requestDelegate;
     _acceptSubroutes = acceptSubroutes;
 }
Exemplo n.º 6
0
 public RouteHandlerDelegate(HandleRequestDelegate requestDelegate, bool acceptSubroutes = false, bool acceptWebsockets = false)
 {
     _delegate = requestDelegate;
     _acceptSubroutes = acceptSubroutes;
 }
 public void Register(string requestName, HandleRequestDelegate call)
 {
     _routes.Add(requestName, call);
 }