コード例 #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);
                    }
                }
            });
        }
コード例 #2
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;
                    }
                }
            });
        }
コード例 #3
0
        protected override void Setup(IOwinApplication host)
        {
            base.Setup(host);

            _api = _host.CreateHttpApi(new JsonSerialiser());

            _api.AddComponent(c =>
            {
                Console.WriteLine(c.RequestUri);
                return(Task.FromResult(0));
            }, OwinPipelineStage.Authenticate);

            foreach (var analyserIFace in _proxy.AnalyserEngine.Analysers.Where(a => a is IHasHttpInterface).Cast <IHasHttpInterface>())
            {
                analyserIFace.Register(_api);
            }

            _api.AddErrorHandler((c, e) =>
            {
                c.Response.CreateTextResponse().Write(e.Message);
                return(Task.FromResult(true));
            });
        }
コード例 #4
0
 protected virtual void Setup(IOwinApplication host)
 {
     _setup = true;
 }
コード例 #5
0
 public HttpAppBase(Uri hostAddress, bool bufferResponse = false)
 {
     _host = hostAddress.CreateOwinApplication(bufferResponse);
     //_host = hostAddress.CreateHttpApplication();
 }