Commit d1dd9545 authored by kevinrmcd's avatar kevinrmcd Committed by GitHub

Update SessionEventArgs.cs

Adding ability to easily create non-200 or non-302 responses.
parent 6bdec0f9
...@@ -417,6 +417,45 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -417,6 +417,45 @@ namespace Titanium.Web.Proxy.EventArguments
WebSession.Request.CancelRequest = true; WebSession.Request.CancelRequest = true;
} }
public async Task GenericResponse(string html, HttpStatusCode status)
        {
            await GenericResponse(html, null, status);
        }
        public async Task GenericResponse(string html, Dictionary<string, HttpHeader> headers, HttpStatusCode status)
        {
            if (WebSession.Request.RequestLocked)
            {
                throw new Exception("You cannot call this function after request is made to server.");
            }
       
            if (html == null)
            {
                html = string.Empty;
            }
            var result = Encoding.Default.GetBytes(html);
            await GenericResponse(result, headers, status);
        }
        public async Task GenericResponse(byte[] result, Dictionary<string, HttpHeader> headers, HttpStatusCode status)
        {
            var response = new GenericResponse(status);
            if (headers != null && headers.Count > 0)
            {
                response.ResponseHeaders = headers;
            }
            response.HttpVersion = WebSession.Request.HttpVersion;
            response.ResponseBody = result;
            await Respond(response);
            WebSession.Request.CancelRequest = true;
        }
public async Task Redirect(string url) public async Task Redirect(string url)
{ {
...@@ -452,4 +491,4 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -452,4 +491,4 @@ namespace Titanium.Web.Proxy.EventArguments
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment