Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #121 from xpicio/develop
Browse files Browse the repository at this point in the history
When the request is not an `application/x-www-form-urlencoded` the `SentryRequest.Data` is empty. This is fixed such that the HTTP body is converted to a `string` otherwise.
  • Loading branch information
asbjornu committed Apr 19, 2016
2 parents a835694 + 2188bd7 commit a860540
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/app/SharpRaven/Data/SentryRequestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
using System.Reflection;

using Newtonsoft.Json;
using System.IO;
using System.Text;

namespace SharpRaven.Data
{
Expand Down Expand Up @@ -97,7 +99,7 @@ public ISentryRequest Create()
Environment = Convert(x => x.Request.ServerVariables),
Headers = Convert(x => x.Request.Headers),
Cookies = Convert(x => x.Request.Cookies),
Data = Convert(x => x.Request.Form),
Data = BodyConvert(),
QueryString = HttpContext.Request.QueryString.ToString()
};

Expand All @@ -119,6 +121,40 @@ public virtual SentryRequest OnCreate(SentryRequest request)
}


private static object BodyConvert()
{
if (!HasHttpContext)
return null;

try
{
if (HttpContext.Request.Form.Count > 0)
{
return Convert(x => x.Request.Form);
}
else
{
string body = String.Empty;

using (MemoryStream stream = new MemoryStream())
{
HttpContext.Request.InputStream.Seek(0, SeekOrigin.Begin);
HttpContext.Request.InputStream.CopyTo(stream);
body = Encoding.UTF8.GetString(stream.ToArray());
}

return body;
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
}

return null;
}


private static IDictionary<string, string> Convert(Func<dynamic, NameObjectCollectionBase> collectionGetter)
{
if (!HasHttpContext)
Expand Down

0 comments on commit a860540

Please sign in to comment.