Beispiel #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;
            }
 		}
Beispiel #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;
     }
 }
Beispiel #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);
        }
Beispiel #4
0
 public override void Respond(ParsedRequest request)
 {
     request.Request.Response.WriteResource(name, contentType);
 }
Beispiel #5
0
 public virtual void Respond(ParsedRequest request)
 {
     handler(request);
 }
Beispiel #6
0
		public override void Respond(ParsedRequest request) {
			request.Request.Response.WriteResource(name, contentType);
		}
Beispiel #7
0
		public virtual void Respond(ParsedRequest request) {
			handler(request);
		}
Beispiel #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);
		}