Esempio n. 1
0
        static void IndexHandler(MiniRequest req, MiniResponse resp)
        {
            string requestBody = req.GetBody();
            string requestStr2 = req.GetBody();

            resp.SetBody(requestStr2);
        }
Esempio n. 2
0
        /// <summary>
        /// URL dispatch/router
        /// </summary>
        /// <param name="context"></param>
        private void ProcessRequest(HttpListenerContext context)
        {
            bool isHandled = false;

            HttpListenerRequest request = context.Request;

            foreach (var handler in _registeredHandlers)
            {
                if (handler.UrlPattern.IsMatch(request.RawUrl) && handler.HttpMethod == context.Request.HttpMethod)
                {
                    MiniRequest  req  = new MiniRequest(context.Request);
                    MiniResponse resp = new MiniResponse(context.Response);

                    handler.RequestHandler(req, resp);
                    resp.Finish();

                    isHandled = true;
                    break; //it's been handled, stop propagation
                }
            }

            if (!isHandled)
            {
                DefaultHander(context);
            }
        }