Exemplo n.º 1
0
        public async void RequestWrongETagReceivesFile()
        {
            var bytes   = LoadSampleJpeg();
            var content = new StaticContent(bytes, ContentTypes.ImageJpeg);

            await Context.Application.Start(new StartServerOptions
            {
                AllowLocalhostOnly = true
            });

            var address = LaraUI.GetFirstURL(Context.Application.GetHost());

            Context.Application.PublishFile("/", content);

            var request = new HttpRequestMessage
            {
                Method     = new HttpMethod("GET"),
                RequestUri = new Uri(address)
            };

            request.Headers.TryAddWithoutValidation("If-None-Match", "lalalalala");

            using var response = await Client.SendAsync(request);

            var downloaded = await response.Content.ReadAsByteArrayAsync();

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.True(response.Headers.TryGetValues("ETag", out var values));
            Assert.Equal(content.ETag, values.FirstOrDefault());
            Assert.Equal(bytes, downloaded);
        }
Exemplo n.º 2
0
        public async void RequestCorrectETagReceivesNotModified()
        {
            var bytes   = LoadSampleJpeg();
            var content = new StaticContent(bytes, ContentTypes.ImageJpeg);

            await Context.Application.Start();

            var address = LaraUI.GetFirstURL(Context.Application.GetHost());

            Context.Application.PublishFile("/", content);

            var request = new HttpRequestMessage
            {
                Method     = new HttpMethod("GET"),
                RequestUri = new Uri(address)
            };

            request.Headers.TryAddWithoutValidation("If-None-Match", content.ETag);

            using var response = await Client.SendAsync(request);

            var downloaded = await response.Content.ReadAsByteArrayAsync();

            Assert.Equal(HttpStatusCode.NotModified, response.StatusCode);
            Assert.False(response.Headers.Contains("ETag"));
            Assert.Empty(downloaded);
        }
Exemplo n.º 3
0
        public async void ContentNotFound()
        {
            await Context.Application.Start();

            var address = LaraUI.GetFirstURL(Context.Application.GetHost());

            using var response = await Client.GetAsync(address + "/lalala");

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
Exemplo n.º 4
0
        public static void Main()
        {
            // create home page
            LaraUI.Publish("/", () => new KitchenSinkForm());

            // start web server
            var host = LaraUI.StartServer().Result;

            // get address (default setting is to assign a dynamic port)
            string address = LaraUI.GetFirstURL(host);

            // run application
            using (var session = MagnetoApp.CreateForm(new Uri(address)))
            {
                ConfigureConfirmExit(session);
                session.RunApplication();
            }
        }
Exemplo n.º 5
0
        public async void RequestWithoutETagReceivesFile()
        {
            var bytes   = LoadSampleJpeg();
            var content = new StaticContent(bytes, ContentTypes.ImageJpeg);

            await Context.Application.Start();

            var address = LaraUI.GetFirstURL(Context.Application.GetHost());

            Context.Application.PublishFile("/", content);
            using var response = await Client.GetAsync(address);

            var downloaded = await response.Content.ReadAsByteArrayAsync();

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.True(response.Headers.TryGetValues("ETag", out var values));
            Assert.Equal(content.ETag, values.FirstOrDefault());
            Assert.Equal(bytes, downloaded);
        }
Exemplo n.º 6
0
        public async void CompressibleFileIsSentCompressed()
        {
            var bytes   = LoadCompressibleBmp();
            var content = new StaticContent(bytes, "image");

            await Context.Application.Start();

            var address = LaraUI.GetFirstURL(Context.Application.GetHost());

            Context.Application.PublishFile("/", content);
            using var response = await Client.GetAsync(address);

            var downloaded = await response.Content.ReadAsByteArrayAsync();

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.True(response.Headers.TryGetValues("ETag", out var values));
            Assert.Equal(content.ETag, values.FirstOrDefault());
            Assert.Equal(bytes, downloaded);
        }