Exemple #1
0
        internal bool FindRoute(string path, out HttpRouteDescription routeDescription)
        {
            var _path = path.StartsWith("/")
                ? path.Substring(1) : path;

            return(routeList.TryGetValue(_path, out routeDescription));
        }
Exemple #2
0
        internal IHttpHandler GetHandler(HttpRouteDescription routeDescription, HttpListenerContext httpContext, HttpReceiverContext context)
        {
            if (!(Activator.CreateInstance(routeDescription.ClassType) is IHttpHandler handler))
            {
                throw new ApplicationException($"Unable to construct HttpHandler implementation '{routeDescription.ClassType.Name}'!");
            }

            handler.HttpContext = httpContext;
            handler.Context     = context;
            handler.OnRequestReceived();
            return(handler);
        }
Exemple #3
0
        public void Scan(Assembly assembly)
        {
            var typeList = assembly.DefinedTypes
                           .Where(t => t.IsClass && !t.IsAbstract);

            foreach (var classType in typeList)
            {
                var attrList = classType.GetCustomAttributes <HttpHandlerAttribute>();

                var attrSecure = classType.GetCustomAttribute <SecureAttribute>();

                foreach (var attr in attrList)
                {
                    var _path = attr.Path.StartsWith("/")
                        ? attr.Path.Substring(1) : attr.Path;

                    routeList[_path] = new HttpRouteDescription {
                        ClassType = classType,
                        IsSecure  = attrSecure != null,
                    };
                }
            }
        }