public JSONRequest(ParsedRequest parent) : base(parent.Request, parent.Parameters) { if (parent.Request.ContentType == "application/json") { byte[] dataBytes = parent.Request.ReadBytes(); string data = dataBytes == null ? null : Encoding.UTF8.GetString(dataBytes); object body = JSON.ToObject(data); if (!(body is Dictionary<string, object>)) throw new HttpException(400, "Body was application/json, but decoded as a " + (body==null ? "null" : body.GetType().Name) + " rather than Dictionary"); Body = (Dictionary<string, object>)body; } }
public JSONRequest(ParsedRequest parent) : base(parent.Request, parent.Parameters) { if (parent.Request.ContentType == "application/json") { byte[] dataBytes = parent.Request.ReadBytes(); string data = dataBytes == null ? null : Encoding.UTF8.GetString(dataBytes); object body = JSON.ToObject(data); if (!(body is Dictionary <string, object>)) { throw new HttpException(400, "Body was application/json, but decoded as a " + (body == null ? "null" : body.GetType().Name) + " rather than Dictionary"); } Body = (Dictionary <string, object>)body; } }
public override void Respond(ParsedRequest request) { JSONRequest jreq = new JSONRequest(request); JSONResponse jres = null; try { jres = Respond(jreq); } catch (Exception e) { if (e is HttpException) { throw e; } jres = GetExceptionResponse(e); } WriteJSONResponse(jres, request.Request.Response); }
public override void Respond(ParsedRequest request) { request.Request.Response.WriteResource(name, contentType); }
public virtual void Respond(ParsedRequest request) { handler(request); }
public override void Respond(ParsedRequest request) { JSONRequest jreq = new JSONRequest(request); JSONResponse jres = null; try { jres = Respond(jreq); } catch (Exception e) { if (e is HttpException) throw e; jres = GetExceptionResponse(e); } WriteJSONResponse(jres, request.Request.Response); }