Skip to content
Open
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
6 changes: 3 additions & 3 deletions Flux.Test/Flux.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="GetRequestParseTest.cs" />
<Compile Include="HeaderParserTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="RequestLineParserTest.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
Expand All @@ -73,6 +70,9 @@
<Name>Flux</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
7 changes: 7 additions & 0 deletions Flux.Test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Flux.Test
===
- At the moment this project is empty because it tested Flux types now implemented by [HttpHelpers](https://github.com/gsscoder/httphelpers).
- I leave the project in the solution for host new test classes.

Giacomo Stelluti Scala
gsscoder@gmail.com
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Flux.sln.DotSettings.user
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<s:Boolean x:Key="/Default/Environment/SearchAndNavigation/MergeOccurences/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestSessionPersistentData/=A552F535564F4684921AF57D39BD034A/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestSessionPersistentData/=A552F535564F4684921AF57D39BD034A/Name/@EntryValue">GetRequestParseTest</s:String>
<s:String x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestSessionPersistentData/=A552F535564F4684921AF57D39BD034A/XmlSerializedElements/@EntryValue">&lt;Session&gt;&lt;Elements&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.GetRequestParseTest" type="XunitTestClassElement" projectId="89BBC848-4B77-4274-B55A-FCE33AA1F9FA" typeName="Flux.Test.GetRequestParseTest" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.HeaderParserTest" type="XunitTestClassElement" projectId="89BBC848-4B77-4274-B55A-FCE33AA1F9FA" typeName="Flux.Test.HeaderParserTest" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.RequestLineParserTest" type="XunitTestClassElement" projectId="89BBC848-4B77-4274-B55A-FCE33AA1F9FA" typeName="Flux.Test.RequestLineParserTest" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestClassElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest.OneHundredConcurrentSimpleGet" ParentId="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestMethodElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" methodName="OneHundredConcurrentSimpleGet" skipReason="" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.HeaderParserTest.ParsesHeaders" ParentId="xunit:Flux.Test.HeaderParserTest" type="XunitTestMethodElement" projectId="89BBC848-4B77-4274-B55A-FCE33AA1F9FA" typeName="Flux.Test.HeaderParserTest" methodName="ParsesHeaders" skipReason="" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.RequestLineParserTest.ParsesRequestLine" ParentId="xunit:Flux.Test.RequestLineParserTest" type="XunitTestMethodElement" projectId="89BBC848-4B77-4274-B55A-FCE33AA1F9FA" typeName="Flux.Test.RequestLineParserTest" methodName="ParsesRequestLine" skipReason="" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.GetRequestParseTest.ParsesRequestLineAndHeadersFromStream" ParentId="xunit:Flux.Test.GetRequestParseTest" type="XunitTestMethodElement" projectId="89BBC848-4B77-4274-B55A-FCE33AA1F9FA" typeName="Flux.Test.GetRequestParseTest" methodName="ParsesRequestLineAndHeadersFromStream" skipReason="" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest.SimpleGet" ParentId="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestMethodElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" methodName="SimpleGet" skipReason="" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest.SimpleGetTwiceOnSameConnection" ParentId="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestMethodElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" methodName="SimpleGetTwiceOnSameConnection" skipReason="" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest.TenConcurrentSimpleGet" ParentId="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestMethodElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" methodName="TenConcurrentSimpleGet" skipReason="" /&gt;&lt;/Elements&gt;&lt;/Session&gt;</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/Housekeeping/UnitTestingMru/UnitTestSessionPersistentData/=A552F535564F4684921AF57D39BD034A/XmlSerializedElements/@EntryValue">&lt;Session&gt;&lt;Elements&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestClassElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest.OneHundredConcurrentSimpleGet" ParentId="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestMethodElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" methodName="OneHundredConcurrentSimpleGet" skipReason="" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest.SimpleGet" ParentId="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestMethodElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" methodName="SimpleGet" skipReason="" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest.SimpleGetTwiceOnSameConnection" ParentId="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestMethodElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" methodName="SimpleGetTwiceOnSameConnection" skipReason="" /&gt;&lt;UnitTestElement Provider="xUnit" Id="xunit:Flux.Test.SimpleWeb.WebClientGetTest.TenConcurrentSimpleGet" ParentId="xunit:Flux.Test.SimpleWeb.WebClientGetTest" type="XunitTestMethodElement" projectId="ED3834CC-2672-4045-A303-F153C87BE806" typeName="Flux.Test.SimpleWeb.WebClientGetTest" methodName="TenConcurrentSimpleGet" skipReason="" /&gt;&lt;/Elements&gt;&lt;/Session&gt;</s:String></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#region License
//
// Http Helpers Library: CharExtensions.cs
//
// Author:
// Giacomo Stelluti Scala (gsscoder@gmail.com)
//
// Copyright (C) 2013 Giacomo Stelluti Scala
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion

namespace HttpHelpers.Extensions
{
static class CharExtensions
{
public static bool IsWhiteSpace(this char c)
{
switch (c)
{
// Regular
case '\f':
case '\v':
case ' ':
case '\t':
return true;

// Unicode
default:
return (c > 127 && char.IsWhiteSpace(c));
}
}

public static bool IsLineTerminator(this char c)
{
switch (c)
{
case '\xD':
case '\xA':
case '\x2028':
case '\x2029':
return true;

default:
return false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#region License
//
// Http Helpers Library: StringExtensions.cs
//
// Author:
// Giacomo Stelluti Scala (gsscoder@gmail.com)
//
// Copyright (C) 2013 Giacomo Stelluti Scala
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
#region Using Directives
using System.Linq;
#endregion

namespace HttpHelpers.Extensions
{
static class StringExtensions
{
public static string TrimStartIf(this string value, char c)
{
return !string.IsNullOrEmpty(value) && c == value[0] ? value.TrimStart(c) : value;
}

public static string TrimStartIf(this string value, params char[] chars)
{
return !string.IsNullOrEmpty(value) && chars.Any(c => c == value[0]) ? value.TrimStart(chars) : value;
}

public static string TrimEndIf(this string value, char c)
{
return !string.IsNullOrEmpty(value) && c == value[0] ? value.TrimEnd(c) : value;
}

//public static string TrimStartWhen(this string value, Func<char, bool> match)
//{
// if (string.IsNullOrEmpty(value))
// {
// return value;
// }
// value.t
//}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#region License
//
// Http Helpers Library: StringReaderExtensions.cs
//
// Author:
// Giacomo Stelluti Scala (gsscoder@gmail.com)
//
// Copyright (C) 2013 Giacomo Stelluti Scala
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
#region Using Directives
using System;
using System.IO;
using System.Text;
#endregion

namespace HttpHelpers.Extensions
{
static class StringReaderExtensions
{
public static string TakeWhile(this StringReader reader, Func<char, bool> predicate)
{
var builder = new StringBuilder();
while (true)
{
var raw = reader.Peek();
if (raw == -1)
{
break;
}
var ch = (char)raw;
if (!predicate(ch))
{
break;
}
builder.Append(ch);
reader.Read();
}
return builder.ToString();
}

public static void SkipWhiteSpace(this StringReader reader)
{
while (true)
{
var raw = reader.Peek();
if (raw == -1)
{
break;
}
var ch = (char)raw;
if (!ch.IsWhiteSpace())
{
break;
}
reader.Read();
}
}

public static int SkipWhile(this StringReader reader, Func<char, bool> predicate)
{
var skipped = 0;
while (true)
{
var raw = reader.Peek();
if (raw == -1)
{
break;
}
var ch = (char)raw;
if (!predicate(ch))
{
break;
}
skipped++;
reader.Read();
}
return skipped;
}

public static char PeekChar(this StringReader reader)
{
return (char) reader.Peek();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#region License
//
// Http Helpers Library: HttpParser.RawParser.cs
//
// Author:
// Giacomo Stelluti Scala (gsscoder@gmail.com)
//
// Copyright (C) 2013 Giacomo Stelluti Scala
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
#region Using Directives
using System;
using System.IO;
using HttpHelpers.Extensions;
#endregion

namespace HttpHelpers
{
partial class HttpParser
{
private static class RawParser
{
public static bool ParseHeadingLine(string line, Action<string, string, string> onHeadingLine)
{
if (string.IsNullOrWhiteSpace(line))
{
return false;
}

var stringReader = new StringReader(line);

var item1 = stringReader.TakeWhile(c => !c.IsWhiteSpace());
if (!stringReader.PeekChar().IsWhiteSpace())
{
return false;
}
stringReader.SkipWhiteSpace();

var item2 = stringReader.TakeWhile(c => !c.IsWhiteSpace());
if (!stringReader.PeekChar().IsWhiteSpace())
{
return false;
}
stringReader.SkipWhiteSpace();

var item3 = stringReader.ReadToEnd();

onHeadingLine(item1, item2, item3);

return true;
}

public static bool ParseHeaderLine(string line, Action<string, string> onHeaderLine)
{
var stringReader = new StringReader(line);

stringReader.SkipWhiteSpace();

var header = stringReader.TakeWhile(c => c != '\x3A');
if (stringReader.PeekChar() != '\x3A')
{
return false;
}
stringReader.Read();

stringReader.SkipWhiteSpace();

var value = stringReader.ReadToEnd();

onHeaderLine(header, value ?? string.Empty);

return true;
}
}
}
}
Loading