Created
March 24, 2015 09:45
-
-
Save grumpydev/3189d453ef24d19d6500 to your computer and use it in GitHub Desktop.
Extension method for Nancy.Response to get the contents as a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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