Skip to content

Commit

Permalink
Merge pull request #15 from rpetrano/invalid_request_crash_fix
Browse files Browse the repository at this point in the history
Fixed crash on Mono when request is invalid.
  • Loading branch information
zapov committed Aug 19, 2014
2 parents faa387c + 0f2425c commit f05dffc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
19 changes: 13 additions & 6 deletions Code/Server/Revenj.Http/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,20 @@ private void ProcessMessageThread(object state)
}
}

private static void ReturnError(HttpListenerResponse response, int status, string message)
private void ReturnError(HttpListenerResponse response, int status, string message)
{
response.StatusCode = status;
response.ContentType = "text/plain; charset=\"utf-8\"";
response.ContentLength64 = Encoding.UTF8.GetByteCount(message);
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(message)))
ms.CopyTo(response.OutputStream);
// Response is disposed before ReturnError is called when sent request is invalid.
// This inner try-catch prevents application crash because of that.
try {
response.StatusCode = status;
response.ContentType = "text/plain; charset=\"utf-8\"";
response.ContentLength64 = Encoding.UTF8.GetByteCount(message);
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(message)))
ms.CopyTo(response.OutputStream);
} catch (Exception ex) {
Console.WriteLine(ex.Message);
Logger.Error(ex.ToString());
}
}
}
}
3 changes: 0 additions & 3 deletions Code/Server/Revenj.Http/Revenj.Http.Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\Revenj.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
6 changes: 1 addition & 5 deletions Code/Server/Revenj.SignalRWeb/Revenj.SignalRWeb.Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BBB38E0A-2C15-4752-9628-6BC6984C4C22}</ProjectGuid>
<ProjectTypeGuids>{349C5851-65DF-11DA-9384-00065B846F21};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down Expand Up @@ -32,9 +31,6 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\Revenj.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
6 changes: 1 addition & 5 deletions Code/Server/Revenj.Wcf/Revenj.Wcf.Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{30CDA3F6-A7A1-499B-B209-118079235745}</ProjectGuid>
<ProjectTypeGuids>{349C5851-65DF-11DA-9384-00065B846F21};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down Expand Up @@ -205,9 +204,6 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\Revenj.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down

0 comments on commit f05dffc

Please sign in to comment.