Skip to content

JsConfig Scope spill over to normal requests #683

@dlj

Description

@dlj

Hello

Using HttpResult with ResultScope, as written in the documentation, seem to have an effect on other calls.
If a request is called after, sporadically the default JsConfig does not seem to apply.

Crude reproduction included, reproduced on SS 5.6.1

using Funq;
using ServiceStack;
using ServiceStack.Text;
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;

namespace WebApplication1
{
    public class TestResponse
    {
        public int Id { get; set; }
        public int? nullableint { get; set; }
        public DateTime tmpDate { get; set; } = DateTime.UtcNow;
    }

    public class GetNormal { }
    public class GetHTTPResultWithResultScope { }

    public class MysService : Service
    {
        public object Get(GetNormal request)
        {
            return new TestResponse() { Id = 1 };
        }

        public object Get(GetHTTPResultWithResultScope request)
        {
            return new HttpResult(new TestResponse() { Id = 1 })
            {
                ResultScope = () => ServiceStack.Text.JsConfig.With(new ServiceStack.Text.Config { IncludeNullValues = true, DateHandler = DateHandler.UnixTime })
            };
        }
    }

    public class Global : System.Web.HttpApplication
    {
        const string URL = "http://localhost:54321";
        protected void Application_Start(object sender, EventArgs e)
        {
            var service = new RestService();
            service.Init();

            load();
        }

        public async Task loadhttp()
        {
            var client = new HttpClient();
            var x = await client.GetAsync($"{URL}/json/reply/GetHTTPResultWithResultScope");
            var body = await x.Content.ReadAsStringAsync();

            if (body.Contains("null"))
            {
                Debug.WriteLine($"HttpResult : Body had Null, Everything is okay");
            }
        }

        public async Task loadnormal(int i = 0)
        {
            var client = new HttpClient();
            var x = await client.GetAsync($"{URL}/json/reply/GetNormal");
            var body = await x.Content.ReadAsStringAsync();

            if (body.Contains("null"))
            {
                Debug.WriteLine($"Iteration {i} : Warning, Body had Null");
                throw new Exception("This should not be null");
            }
        }

        public async void load()
        {
            await loadnormal();
            await loadhttp();
            for (int i = 0; i < 100; i++)
            {
                await loadnormal(i);
            }

        }
    }

    public class RestService : AppHostHttpListenerBase
    {
        public RestService() : base("RestService", typeof(Global).Assembly)
        {

        }

        public override void Configure(Container container)
        {
            JsConfig.Init(new ServiceStack.Text.Config
            {
                IncludeNullValues = false,
                DateHandler = DateHandler.ISO8601
            });

            SetConfig(new HostConfig
            {
                DebugMode = true,
                StrictMode = true,
            });
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions