diff --git a/Mindscape.Raygun4Net.WebApi/RaygunWebApiClient.cs b/Mindscape.Raygun4Net.WebApi/RaygunWebApiClient.cs index 4d9362cf..0aa3820a 100644 --- a/Mindscape.Raygun4Net.WebApi/RaygunWebApiClient.cs +++ b/Mindscape.Raygun4Net.WebApi/RaygunWebApiClient.cs @@ -133,8 +133,7 @@ private static void AttachInternal(HttpConfiguration config, Func a.FullName.StartsWith("Owin")); - if (owinAssembly == null) + if (RaygunSettings.Settings.IsRawDataIgnored == false) { config.MessageHandlers.Add(new RaygunWebApiDelegatingHandler()); } diff --git a/Mindscape.Raygun4Net.WebApi/RaygunWebApiDelegatingHandler.cs b/Mindscape.Raygun4Net.WebApi/RaygunWebApiDelegatingHandler.cs index 6e4f9378..cfd38bd6 100644 --- a/Mindscape.Raygun4Net.WebApi/RaygunWebApiDelegatingHandler.cs +++ b/Mindscape.Raygun4Net.WebApi/RaygunWebApiDelegatingHandler.cs @@ -1,5 +1,4 @@ -using System.ComponentModel; -using System.Linq; +using System.Linq; using System.Net.Http; using System.Text; @@ -11,21 +10,13 @@ public class RaygunWebApiDelegatingHandler : DelegatingHandler protected override async System.Threading.Tasks.Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { - var stream = await request.Content.ReadAsStreamAsync(); - if (stream != null && stream.CanSeek) + // ReadAsByteArrayAsync is always readable as it calls LoadIntoBufferAsync internally. + var bytes = await request.Content.ReadAsByteArrayAsync(); + if (bytes.Length > 0) { - var lengthToRead = (int)(stream.Length < 4096 ? stream.Length : 4096); - var buffer = new byte[lengthToRead]; - - await stream.ReadAsync(buffer, 0, lengthToRead, cancellationToken); - - var body = Encoding.UTF8.GetString(buffer); - if (!string.IsNullOrEmpty(body)) - { - request.Properties[RequestBodyKey] = body; - } - - stream.Seek(0, System.IO.SeekOrigin.Begin); + // Only take first 4096 bytes + var bytesToSend = bytes.Take(4096).ToArray(); + request.Properties[RequestBodyKey] = Encoding.UTF8.GetString(bytesToSend); } return await base.SendAsync(request, cancellationToken);