Example #1
0
 public static void Callback(RoutedHttpRequest request, HttpListenerResponse response)
 {
     Console.WriteLine(request.Request.Url);
       foreach (var param in request.Params)
       {
     Console.WriteLine("{0}={1}", param.Key, param.Value);
       }
       response.StatusCode = 200;
       response.OutputStream.Close();
 }
Example #2
0
        public void HandleRequest(string request, HttpListenerContext httpContext)
        {
            // normalize all requests to not have a trailing slash
              request = request.TrimEnd('/');

              // filter the routes to try by their http method type.
              var routes = _routes.Where(route => string.Equals(route.HttpMethod.ToString(), httpContext.Request.HttpMethod, StringComparison.InvariantCultureIgnoreCase));
              foreach (var route in routes)
              {
            var match = route.Regex.Match(request);
            if (match.Success)
            {
              // get the params from the endpoint for this route.
              var @params = route.GetParams(match);
              // compose the HttpListenerRequest with the endpoint's params.
              var routedRequest = new RoutedHttpRequest(httpContext.Request, @params);

              // raise the callback and return.
              route.Callback(routedRequest, httpContext.Response);
              return;
            }
              }
        }