private static Task SendJsonResponse(HostContext context, string jsonPayload)
{
var callback = context.Request.QueryString["callback"];
if (String.IsNullOrEmpty(callback))
{
// Send normal JSON response
context.Response.ContentType = JsonUtility.JsonMimeType;
return context.Response.End(jsonPayload);
}
// Send JSONP response since a callback is specified by the query string
var callbackInvocation = JsonUtility.CreateJsonpCallback(callback, jsonPayload);
context.Response.ContentType = JsonUtility.JavaScriptMimeType;
return context.Response.End(callbackInvocation);
}