From eea309281a7462e28dde2b8a4ef3615daca93145 Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Sun, 1 Jan 2012 02:30:49 -0700 Subject: [PATCH] Added a disabled RestRequestEvent hook --- TShockAPI/Rest/Rest.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/TShockAPI/Rest/Rest.cs b/TShockAPI/Rest/Rest.cs index 31043f8e..1e219e90 100644 --- a/TShockAPI/Rest/Rest.cs +++ b/TShockAPI/Rest/Rest.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Net; using System.Text; using System.Text.RegularExpressions; using HttpServer; using HttpServer.Headers; using Newtonsoft.Json; +using TShockAPI; using HttpListener = HttpServer.HttpListener; namespace Rests @@ -68,12 +70,38 @@ namespace Rests commands.Add(com); } + #region Event + public class RestRequestEventArgs : HandledEventArgs + { + public RequestEventArgs Request { get; set; } + } + + public static HandlerList RestRequestEvent; + + private static bool OnRestRequestCall(RequestEventArgs request) + { + if (RestRequestEvent == null) + return false; + + var args = new RestRequestEventArgs + { + Request = request, + }; + RestRequestEvent.Invoke(null, args); + return args.Handled; + } + #endregion + + protected virtual void OnRequest(object sender, RequestEventArgs e) { var obj = ProcessRequest(sender, e); if (obj == null) throw new NullReferenceException("obj"); + //if (OnRestRequestCall(e)) + // return; + var str = JsonConvert.SerializeObject(obj, Formatting.Indented); e.Response.Connection.Type = ConnectionType.Close; e.Response.Body.Write(Encoding.ASCII.GetBytes(str), 0, str.Length);