Skip to content

Instantly share code, notes, and snippets.

@grumpydev
Created March 24, 2015 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grumpydev/3189d453ef24d19d6500 to your computer and use it in GitHub Desktop.
Save grumpydev/3189d453ef24d19d6500 to your computer and use it in GitHub Desktop.
Extension method for Nancy.Response to get the contents as a string
namespace Nancy.Extensions
{
using System.IO;
using System.Text;
public static class ResponseExtensions
{
public static string ToString(this Response response, Encoding encoding = null)
{
var actualEncoding = encoding ?? Encoding.UTF8;
using (var buffer = new MemoryStream())
{
response.Contents.Invoke(buffer);
var bufferArray = buffer.ToArray();
return actualEncoding.GetString(bufferArray);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment