Ejemplo n.º 1
0
		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;
            }
 		}
Ejemplo n.º 2
0
 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;
     }
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public override void Respond(ParsedRequest request)
 {
     request.Request.Response.WriteResource(name, contentType);
 }
Ejemplo n.º 5
0
 public virtual void Respond(ParsedRequest request)
 {
     handler(request);
 }
Ejemplo n.º 6
0
		public override void Respond(ParsedRequest request) {
			request.Request.Response.WriteResource(name, contentType);
		}
Ejemplo n.º 7
0
		public virtual void Respond(ParsedRequest request) {
			handler(request);
		}
Ejemplo n.º 8
0
		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);
		}