/// <summary> /// /// </summary> /// <param name="context"></param> protected void SetStatus(IHttpRequestResponseContext context) { context.Response.StatusCode = statusCode; if (statusDescription != null) { context.Response.StatusDescription = statusDescription; } }
/// <summary> /// /// </summary> /// <param name="context"></param> protected virtual void SetCookie(IHttpRequestResponseContext context) { Action <IHttpRequestResponseContext> handler = CookieHandle; if (handler != null) { handler(context); } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public override async Task Execute(IHttpRequestResponseContext context) { if (data == null) { context.Response.StatusCode = 500; return; } SetStatus(context); SetCookie(context); //js call need context.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (context.Request.QueryString["showjson"] == "1") { context.Response.ContentType = "application/json"; context.Response.SendChunked = false; context.Response.ContentLength64 = data.Length; using (Stream output = context.Response.OutputStream) { await output.WriteAsync(data, 0, data.Length); output.Close(); } } else { context.Response.ContentType = "application/octet-stream"; context.Response.SendChunked = false; int offset = 0; if (!(data.Length > 3 && data[offset] == 0x1f && data[offset + 1] == 0x8b && data[offset + 2] == 0x08 && data[offset + 3] == 0x00) && data.Length > 1024) { context.Response.AddHeader("Content-Encoding", "gzip"); using (MemoryStream ms = new MemoryStream()) using (GZipStream gzs = new GZipStream(ms, CompressionMode.Compress, true)) { gzs.Write(data, 0, data.Length); gzs.Close(); context.Response.ContentLength64 = ms.Length; await context.Response.OutputStream.WriteAsync(ms.GetBuffer(), 0, (int)ms.Length); context.Response.OutputStream.Close(); } } else { context.Response.ContentLength64 = data.Length; using (Stream output = context.Response.OutputStream) { await output.WriteAsync(data, 0, data.Length); output.Close(); } } } }
public override async Task Execute(IHttpRequestResponseContext context) { SetStatus(context); context.Response.ContentLength64 = response.Length; context.Response.SendChunked = false; context.Response.ContentType = "text/html"; using (context.Response.OutputStream) using (var tw = new System.IO.StreamWriter(context.Response.OutputStream, UTF8.WithoutBOM, 65536, true)) await tw.WriteAsync(response); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public override async Task Execute(IHttpRequestResponseContext context) { SetStatus(context); context.Response.ContentType = "application/json; charset=utf-8"; //context.Response.ContentEncoding = UTF8.WithoutBOM; using (context.Response.OutputStream) { var tw = new StreamWriter(context.Response.OutputStream, UTF8.WithoutBOM); Json.Serializer.Serialize(tw, _value); } }
public override async Task Execute(IHttpRequestResponseContext context) { SetStatus(context); context.Response.ContentLength64 = _content.Length; context.Response.SendChunked = false; context.Response.ContentType = _contentType; using (_content) using (context.Response.OutputStream) { await _content.CopyToAsync(context.Response.OutputStream); } }
public override async Task Execute(IHttpRequestResponseContext context) { SetStatus(context); context.Response.ContentType = "application/json; charset=utf-8"; //context.Response.ContentEncoding = UTF8.WithoutBOM; var sb = new StringBuilder(0x400); using (var textWriter = new StringWriter(sb)) Json.Serializer.Serialize(textWriter, _value); using (context.Response.OutputStream) using (var tw = new StreamWriter(context.Response.OutputStream, UTF8.WithoutBOM, 65536, true)) await tw.WriteAsync(sb.ToString()); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public override async Task Execute(IHttpRequestResponseContext context) { if (data == null) { context.Response.StatusCode = 500; return; } SetStatus(context); SetCookie(context); //js call need context.Response.AddHeader("Access-Control-Allow-Origin", "*"); if (context.Request.QueryString["showjson"] == "1") { context.Response.ContentType = "application/json"; context.Response.SendChunked = false; context.Response.ContentLength64 = data.Length; using (Stream output = context.Response.OutputStream) { await output.WriteAsync(data, 0, data.Length); output.Close(); } } else { context.Response.ContentType = "application/octet-stream"; context.Response.SendChunked = false; int offset = 0; if (data.Length > 3 && data[offset] == 0x1f && data[offset + 1] == 0x8b && data[offset + 2] == 0x08 && data[offset + 3] == 0x00) { context.Response.AddHeader("Content-Encoding", "gzip"); } context.Response.ContentLength64 = data.Length; using (Stream output = context.Response.OutputStream) { await output.WriteAsync(data, 0, data.Length); output.Close(); } } }
public async Task Execute(IHttpRequestResponseContext context) { context.Response.StatusCode = statusCode; if (statusDescription != null) { context.Response.StatusDescription = statusDescription; } context.Response.ContentType = "application/json; charset=utf-8"; // NOTE(jsd): Not concerned at all about setting ContentLength64. // NOTE(jsd): This seems to be a hot line re: performance. //context.Response.ContentEncoding = UTF8.WithoutBOM; #if false var rsp = context.Response.OutputStream; using (rsp) { var tw = new StreamWriter(rsp, UTF8.WithoutBOM); Json.Serializer.Serialize(tw, this); tw.Close(); } #else // NOTE(jsd): Just testing out some stuff here... var sb = new StringBuilder(1024); using (var sw = new StringWriter(sb)) { Json.Serializer.Serialize(sw, this); } var rsp = context.Response.OutputStream; var enc = UTF8.WithoutBOM; // Get the response as a single string instance (horrible but apparently the only way to easily calculate // the byte count of the response): var text = sb.ToString(); var bytes = enc.GetBytes(text); // Set the length header: context.Response.ContentLength64 = bytes.LongLength; // Write the response: await rsp.WriteAsync(bytes, 0, bytes.Length); #endif }
public async Task Execute(IHttpRequestResponseContext context) { context.Response.StatusCode = statusCode; if (statusDescription != null) context.Response.StatusDescription = statusDescription; context.Response.ContentType = "application/json; charset=utf-8"; // NOTE(jsd): Not concerned at all about setting ContentLength64. // NOTE(jsd): This seems to be a hot line re: performance. //context.Response.ContentEncoding = UTF8.WithoutBOM; #if false var rsp = context.Response.OutputStream; using (rsp) { var tw = new StreamWriter(rsp, UTF8.WithoutBOM); Json.Serializer.Serialize(tw, this); tw.Close(); } #else // NOTE(jsd): Just testing out some stuff here... var sb = new StringBuilder(1024); using (var sw = new StringWriter(sb)) { Json.Serializer.Serialize(sw, this); } var rsp = context.Response.OutputStream; var enc = UTF8.WithoutBOM; // Get the response as a single string instance (horrible but apparently the only way to easily calculate // the byte count of the response): var text = sb.ToString(); var bytes = enc.GetBytes(text); // Set the length header: context.Response.ContentLength64 = bytes.LongLength; // Write the response: await rsp.WriteAsync(bytes, 0, bytes.Length); #endif }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public abstract Task Execute(IHttpRequestResponseContext context);
/// <summary> /// /// </summary> /// <param name="context"></param> protected virtual void SetCookie(IHttpRequestResponseContext context) { Action<IHttpRequestResponseContext> handler = CookieHandle; if (handler != null) handler(context); }
/// <summary> /// /// </summary> /// <param name="context"></param> protected void SetStatus(IHttpRequestResponseContext context) { context.Response.StatusCode = statusCode; if (statusDescription != null) context.Response.StatusDescription = statusDescription; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public Task Execute(IHttpRequestResponseContext context) { context.Response.Redirect(Url); return null; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> public Task Execute(IHttpRequestResponseContext context) { context.Response.Redirect(Url); return(null); }