示例#1
0
        public async Task Server_HotRemovePrefix_Success()
        {
            string address;

            using (var server = Utilities.CreateHttpServer(out address))
            {
                address += "pathbase/";
                server.Options.UrlPrefixes.Add(AzureRelayUrlPrefix.Create(address, Utilities.CreateTokenProvider()));
                var responseTask = SendRequestAsync(address);

                var context = await server.AcceptAsync(Utilities.DefaultTimeout);

                Assert.Equal("/pathbase", context.Request.PathBase);
                Assert.Equal("/", context.Request.Path);
                context.Dispose();

                var response = await responseTask;
                Assert.Equal(string.Empty, response);

                Assert.True(server.Options.UrlPrefixes.Remove(address));

                responseTask = SendRequestAsync(address);

                context = await server.AcceptAsync(Utilities.DefaultTimeout);

                Assert.Equal(string.Empty, context.Request.PathBase);
                Assert.Equal("/pathbase/", context.Request.Path);
                context.Dispose();

                response = await responseTask;
                Assert.Equal(string.Empty, response);
            }
        }
示例#2
0
        internal static AzureRelayListener CreateServer(string baseUrl, string path)
        {
            var listener = new AzureRelayListener(new AzureRelayOptions()
            {
                TokenProvider = Microsoft.Azure.Relay.AspNetCore.Utilities.CreateTokenProvider()
            }, new LoggerFactory());

            listener.Options.UrlPrefixes.Add(AzureRelayUrlPrefix.Create(new Uri(new Uri(baseUrl), path).AbsoluteUri));
            listener.Start();
            return(listener);
        }
示例#3
0
        internal static AzureRelayListener CreateDynamicHttpServer(string basePath, out string root, out string baseAddress, TokenProvider tp = null)
        {
            if (basePath.StartsWith("/"))
            {
                basePath = basePath.Substring(1);
            }
            var rootUri = new Uri(Microsoft.Azure.Relay.AspNetCore.Utilities.GetRelayUrl());
            var prefix  = AzureRelayUrlPrefix.Create(new Uri(rootUri, basePath).AbsoluteUri, tp != null ? tp : CreateTokenProvider());

            root        = rootUri.ToString();
            baseAddress = prefix.FullPrefix;

            var listener = new AzureRelayListener(new AzureRelayOptions(), new LoggerFactory());

            listener.Options.UrlPrefixes.Add(prefix);
            listener.Start();
            return(listener);
        }