Skip to content

Commit

Permalink
Correcting issue #62. Allows text/plain even if it's not registered i…
Browse files Browse the repository at this point in the history
…n the encoder.
  • Loading branch information
jgauffin committed Apr 6, 2016
1 parent d59d370 commit e352e9a
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<Compile Include="Logging\LogManagerTests.cs" />
<Compile Include="Logging\NamespaceFilterTests.cs" />
<Compile Include="Logging\Providers\LogProviderTests.cs" />
<Compile Include="Logging\Subjects\ClassB.cs" />
<Compile Include="Logging\Subjects\ClassA.cs" />
<Compile Include="Logging\Subjects\SomeLogger.cs" />
<Compile Include="Net\Buffers\BufferPoolTests.cs" />
<Compile Include="Net\Buffers\BufferSliceTests.cs" />
<Compile Include="Net\Channels\ClientServerHelper.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Griffin.Logging;

namespace Griffin.Core.Tests.Logging.Subjects
{
internal class ClassA
{
ILogger _logger = LogManager.GetLogger<ClassA>();

public void DoSomething()
{
_logger.Trace("ClassA is doing something.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Griffin.Logging;

namespace Griffin.Core.Tests.Logging.Subjects
{
class ClassB
{
ILogger _logger = LogManager.GetLogger<ClassB>();

public void DoSomething()
{
_logger.Trace("ClassB is doing something.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using Griffin.Logging;
using Griffin.Logging.Loggers;

namespace Griffin.Core.Tests.Logging.Subjects
{
internal class SomeLogger : BaseLogger
{
public SomeLogger(Type type, string name)
: base(type)
{
Name = name;
Entries = new List<LogEntry>();
}

public List<LogEntry> Entries { get; set; }
public string Name { get; }

public override void Write(LogEntry entry)
{
Entries.Add(entry);
}
}
}
18 changes: 9 additions & 9 deletions src/Griffin.Framework/Griffin.Core/Logging/LogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public static ILogProvider Provider
{
get
{
if (_current == null)
if (_current != null)
return _current;

lock (SynLock)
{
lock (SynLock)
if (_current == null)
{
if (_current == null)
{
//not a problem on x86 & x64
// ReSharper disable PossibleMultipleWriteAccessInDoubleCheckLocking
_current = new NullLogProvider();
// ReSharper restore PossibleMultipleWriteAccessInDoubleCheckLocking
}
//not a problem on x86 & x64
// ReSharper disable PossibleMultipleWriteAccessInDoubleCheckLocking
_current = new NullLogProvider();
// ReSharper restore PossibleMultipleWriteAccessInDoubleCheckLocking
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using Griffin.Net.Channels;
using Griffin.Net.Protocols.Http.Messages;
using Griffin.Net.Protocols.Http.Serializers;
Expand Down Expand Up @@ -192,17 +193,24 @@ private void TriggerMessageReceived(HttpMessage message)
{
var result = _messageSerializer.Deserialize(message.Headers["Content-Type"], message.Body);
if (result == null)
throw new BadRequestException("Unsupported content-type: " + message.ContentType);

var formAndFiles = result as FormAndFilesResult;
if (formAndFiles != null)
{
request.Form = formAndFiles.Form;
request.Files = formAndFiles.Files;
//it's a so simple protocol, we can expect that the client can handle it.
if (!"text/plain".Equals(message.Headers["Content-Type"], StringComparison.OrdinalIgnoreCase))
throw new BadRequestException("Unsupported content-type: " + message.ContentType);
}
else
throw new HttpException(500, "Unknown decoder result: " + result);
{
var formAndFiles = result as FormAndFilesResult;
if (formAndFiles != null)
{
request.Form = formAndFiles.Form;
request.Files = formAndFiles.Files;
}
else
throw new HttpException(500, "Unknown decoder result: " + result);
}
}

var cookies = request.Headers["Cookie"];
if (cookies != null)
{
Expand Down

0 comments on commit e352e9a

Please sign in to comment.