So I’m running into an issue where I find myself needing to UrlDecode() parameters on my ServiceModel that come in from a GET request (i.e. over the URL).
My partner thought this should be handled for us by Service Stack automatically. Is there a config switch or something to toggle to enable Automatic UrlDecoding of GET parameters?
I.E. I have a model with a string parameter that in tests works no problem. When hitting the endpoint with a JsonServiceClient, the parameter gets Url-encoded as the request is made. This causes the back-end service model to show up as UrlEncoded text, which returns zero results because it can’t find items based on a URL-encoded parameter. Once I manually UrlDecode the property, all is fine again. I’m just not sure if I should be handling this manually, or does Service Stack have an option to do this for me?
But this test works in both HttpListener and .NET Core Hosts:
[Test]
public void Does_URL_Decode_PathInfo()
{
var client = new JsonServiceClient(Config.HostNameBaseUrl);
var pathInfo = "ern::Closer2U::Userprofile::1c7e9ead-c7d9-46f8-a0cc-2777c4373ac4";
var response = client.Get(new CustomRoute {
Data = pathInfo
});
Assert.That(response.Data, Is.EqualTo(pathInfo));
}
Where CustomRoute is:
[Route("/custom")]
[Route("/custom/{Data}")]
public class CustomRoute : IReturn<CustomRoute>
{
public string Data { get; set; }
}
public class MyServices : Service
{
public object Any(CustomRoute request) => request;
}
The expected raw HTTP Request and Response Headers were sent:
I’m not sure what’s causing your issue, but I’d first try calling the Service locally without going through an AWS proxy in-case that’s causing double-encoding.
Note: the /path/info segment of the URL is part of the URL identifier which is normally a human readable string. It’s not normal to require URL encoding on the path info. instead you can use the ?queryString for any data params. I’d especially avoid using : on the path info which can be flagged as a potentially malicious request.