public void SendResult(ITypeAccepter accepter, object o, Encoding encoding = null) { // Vary: * is basically ignored by browsers Context.Response.Cache.SetOmitVaryStar(true); if (Context.Request.QueryString["jsonp"] != null) { if (!IsSimpleJSIdentifier(Context.Request.QueryString["jsonp"])) { throw new HttpError(400, "Bad Request", "The jsonp parameter must be a simple script identifier."); } SendJson(o); return; } // Check in priority order, since JSON will always be a default. foreach (var type in accepter.AcceptTypes(Context)) { if (type == JsonConstants.MediaType) { SendJson(o); return; } if (type == MediaTypeNames.Text.Xml) { SendXml(o); return; } } SendText(o, encoding); }
public static void SendResult(HttpContext context, ITypeAccepter accepter, object o, Encoding encoding = null) { // Vary: * is basically ignored by browsers context.Response.Cache.SetOmitVaryStar(true); if (context.Request.QueryString["jsonp"] != null) { if (!IsSimpleJSIdentifier(context.Request.QueryString["jsonp"])) { SendError(context.Response, 400, "Bad Request", "The jsonp parameter must be a simple script identifier."); return; } SendJson(context, o); return; } // Check in priority order, since JSON will always be a default. foreach (var type in accepter.AcceptTypes(context)) { if (type == JsonConstants.MediaType) { SendJson(context, o); return; } if (type == MediaTypeNames.Text.Xml) { SendXml(context, o); return; } } SendText(context, o, encoding); }