public async Task<string> ReadAsStringAsync ()
{
await LoadIntoBufferAsync ().ConfigureAwait (false);
if (buffer.Length == 0)
return string.Empty;
var buf = buffer.GetBuffer ();
var buf_length = (int) buffer.Length;
int preambleLength = 0;
Encoding encoding;
if (headers != null && headers.ContentType != null && headers.ContentType.CharSet != null) {
encoding = Encoding.GetEncoding (headers.ContentType.CharSet);
preambleLength = StartsWith (buf, buf_length, encoding.GetPreamble ());
} else {
encoding = GetEncodingFromBuffer (buf, buf_length, ref preambleLength) ?? Encoding.UTF8;
}
return encoding.GetString (buf, preambleLength, buf_length - preambleLength);
}