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

BUG: Restore Request.InputStream position after body has been read #210

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ restore:
mono --runtime=v4.0.30319 ".nuget/nuget.exe" Restore "src"

test: restore
xbuild "./src/SharpRaven.build"
msbuild "./src/SharpRaven.build"
mono --debug --runtime=v4.0.30319 ./src/packages/NUnit.Runners.2.6.4/tools/nunit-console.exe ./src/tests/SharpRaven.UnitTests/bin/Release/net45/SharpRaven.UnitTests.dll -exclude=NuGet,NoMono -nodots
24 changes: 24 additions & 0 deletions src/SharpRaven.sln
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ Global
{156621FC-2C48-4CDF-A368-9347BABE9089}.Release 4.5|Mixed Platforms.ActiveCfg = Release 4.5|Any CPU
{156621FC-2C48-4CDF-A368-9347BABE9089}.Release 4.5|Mixed Platforms.Build.0 = Release 4.5|Any CPU
{156621FC-2C48-4CDF-A368-9347BABE9089}.Release 4.5|x86.ActiveCfg = Release 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 3.5|Any CPU.ActiveCfg = Debug 3.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 3.5|Any CPU.Build.0 = Debug 3.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 3.5|Mixed Platforms.ActiveCfg = Debug 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 3.5|Mixed Platforms.Build.0 = Debug 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 3.5|x86.ActiveCfg = Debug 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 3.5|x86.Build.0 = Debug 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 4.0|Any CPU.ActiveCfg = Debug 4.0|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 4.0|Any CPU.Build.0 = Debug 4.0|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 4.0|Mixed Platforms.ActiveCfg = Debug 4.0|Any CPU
Expand All @@ -171,6 +177,12 @@ Global
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 4.5|Mixed Platforms.ActiveCfg = Debug 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 4.5|Mixed Platforms.Build.0 = Debug 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Debug 4.5|x86.ActiveCfg = Debug 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 3.5|Any CPU.ActiveCfg = Release 3.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 3.5|Any CPU.Build.0 = Release 3.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 3.5|Mixed Platforms.ActiveCfg = Release 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 3.5|Mixed Platforms.Build.0 = Release 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 3.5|x86.ActiveCfg = Release 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 3.5|x86.Build.0 = Release 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 4.0|Any CPU.ActiveCfg = Release 4.0|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 4.0|Any CPU.Build.0 = Release 4.0|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 4.0|Mixed Platforms.ActiveCfg = Release 4.0|Any CPU
Expand All @@ -181,6 +193,12 @@ Global
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 4.5|Mixed Platforms.ActiveCfg = Release 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 4.5|Mixed Platforms.Build.0 = Release 4.5|Any CPU
{ABE22746-6EEB-4970-A608-C02BC3B8BDA3}.Release 4.5|x86.ActiveCfg = Release 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 3.5|Any CPU.ActiveCfg = Debug 3.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 3.5|Any CPU.Build.0 = Debug 3.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 3.5|Mixed Platforms.ActiveCfg = Debug 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 3.5|Mixed Platforms.Build.0 = Debug 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 3.5|x86.ActiveCfg = Debug 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 3.5|x86.Build.0 = Debug 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 4.0|Any CPU.ActiveCfg = Debug 4.0|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 4.0|Any CPU.Build.0 = Debug 4.0|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 4.0|Mixed Platforms.ActiveCfg = Debug 4.0|Any CPU
Expand All @@ -191,6 +209,12 @@ Global
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 4.5|Mixed Platforms.ActiveCfg = Debug 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 4.5|Mixed Platforms.Build.0 = Debug 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Debug 4.5|x86.ActiveCfg = Debug 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release 3.5|Any CPU.ActiveCfg = Release 3.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release 3.5|Any CPU.Build.0 = Release 3.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release 3.5|Mixed Platforms.ActiveCfg = Release 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release 3.5|Mixed Platforms.Build.0 = Release 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release 3.5|x86.ActiveCfg = Release 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release 3.5|x86.Build.0 = Release 4.5|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release 4.0|Any CPU.ActiveCfg = Release 4.0|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release 4.0|Any CPU.Build.0 = Release 4.0|Any CPU
{7FE52A2B-430C-4C6F-BEA9-0855AF973D0C}.Release 4.0|Mixed Platforms.ActiveCfg = Release 4.0|Any CPU
Expand Down
20 changes: 20 additions & 0 deletions src/app/SharpRaven.Nancy/SharpRaven.Nancy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@
<Prefer32Bit>false</Prefer32Bit>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug 3.5|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\net35\</OutputPath>
<DefineConstants>TRACE;DEBUG;net35</DefineConstants>
<DocumentationFile>bin\Debug\net35\SharpRaven.Nancy.xml</DocumentationFile>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release 3.5|AnyCPU'">
<OutputPath>bin\Release\net35\</OutputPath>
<DefineConstants>TRACE;net35</DefineConstants>
<DocumentationFile>bin\Release\net35\SharpRaven.Nancy.xml</DocumentationFile>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Nancy, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Nancy.1.4.3\lib\net40\Nancy.dll</HintPath>
Expand Down
16 changes: 12 additions & 4 deletions src/app/SharpRaven/Data/DefaultHttpRequestBodyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,19 @@ public bool TryConvert(dynamic httpContext, out object converted)
{
using (var stream = new MemoryStream())
{
httpContext.Request.InputStream.Seek(0, SeekOrigin.Begin);
httpContext.Request.InputStream.CopyTo(stream);
converted = Encoding.UTF8.GetString(stream.ToArray());
var position = httpContext.Request.InputStream.Position;
try
{
httpContext.Request.InputStream.Seek(0, SeekOrigin.Begin);
httpContext.Request.InputStream.CopyTo(stream);
converted = Encoding.UTF8.GetString(stream.ToArray());

return true;
return true;
}
finally
{
httpContext.Request.InputStream.Position = position;
}
}
}
catch (Exception exception)
Expand Down
14 changes: 11 additions & 3 deletions src/app/SharpRaven/Data/JsonHttpRequestBodyConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,17 @@ public bool TryConvert(dynamic httpContext, out object converted)

using (var stream = new MemoryStream())
{
httpContext.Request.InputStream.Seek(0, SeekOrigin.Begin);
httpContext.Request.InputStream.CopyTo(stream);
body = Encoding.UTF8.GetString(stream.ToArray());
var position = httpContext.Request.InputStream.Position;
try
{
httpContext.Request.InputStream.Seek(0, SeekOrigin.Begin);
httpContext.Request.InputStream.CopyTo(stream);
body = Encoding.UTF8.GetString(stream.ToArray());
}
finally
{
httpContext.Request.InputStream.Position = position;
}
}

converted = JsonConvert.DeserializeObject<Dictionary<string, object>>(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug 3.5|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\net35\</OutputPath>
<DefineConstants>TRACE;DEBUG;net35</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release 3.5|AnyCPU'">
<OutputPath>bin\Release\net35\</OutputPath>
<DefineConstants>TRACE;net35</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="CsQuery, Version=1.3.3.249, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down