Exemplo n.º 1
0
        protected override void Setup(IOwinApplication host)
        {
            base.Setup(host);

            host.AddComponent(async c =>
            {
                var relPath = c.RequestUri.PathAndQuery == "/" ? ".index.html" : c.RequestUri.PathAndQuery.Replace('/', '.');
                var path    = GetType().Namespace + ".wwwroot.app" + relPath;
                var names   = _asm.GetManifestResourceNames();
                var name    = names.FirstOrDefault(n => DashAgnosticMatch(n, path));

                using (var resource = _asm.GetManifestResourceStream(name ?? path))
                {
                    if (resource == null)
                    {
                        c.Response.CreateStatusResponse(404);
                    }
                    else
                    {
                        var ext = relPath.Split('.').Last().Split('?').First();

                        c.Response.Header.Headers["Cache-Control"] = new [] { "private, max-age=15000" };
                        c.Response.Header.ContentMimeType          = MapMime(ext);

                        await resource.CopyToAsync(c.Response.Content);
                    }
                }
            });
        }
Exemplo n.º 2
0
        public void AllowOrigin(Uri origin)
        {
            _host.AddComponent(c =>
            {
                c.Response.Header.Headers["Access-Control-Allow-Credentials"] = new[] { "true" };
                c.Response.Header.Headers["Access-Control-Allow-Origin"]      = new[] { origin.Scheme + Uri.SchemeDelimiter + origin.Host + ':' + origin.Port };
                c.Response.Header.Headers["Access-Control-Allow-Methods"]     = new[] { "GET, POST, PUT, DELETE, OPTIONS" };
                c.Response.Header.Headers["Access-Control-Allow-Headers"]     = new[] { "Content-Type,X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5,  Date, X-Api-Version, X-File-Name" };

                if (c.Request.Header.HttpVerb == "OPTIONS")
                {
                    c.Response.Header.StatusCode = 200;
                }

                return(Task.FromResult(true));
            }, OwinPipelineStage.Authenticate);
        }
Exemplo n.º 3
0
        protected override void Setup(IOwinApplication host)
        {
            host.AddComponent(async c =>
            {
                using (_analysers.Pause())
                {
                    try
                    {
                        var id    = Guid.NewGuid();
                        int i     = 0;
                        var tasks = _targets.Select(t => ForwardContext(id, (i++ > 0) ? c.Clone(true) : c, t, i > 0)).ToList();

                        await Task.WhenAll(tasks);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        throw ex;
                    }
                }
            });
        }