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 src/Servers/GenHttpServer11/GenHttpServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GenHTTP.Core" Version="11.0.0-preview.9" />
<PackageReference Include="GenHTTP.Modules.Functional" Version="11.0.0-preview.9" />
<PackageReference Include="GenHTTP.Modules.Practices" Version="11.0.0-preview.9" />
<PackageReference Include="GenHTTP.Core" Version="11.0.0-preview.19" />
<PackageReference Include="GenHTTP.Modules.Functional" Version="11.0.0-preview.19" />
<PackageReference Include="GenHTTP.Modules.Practices" Version="11.0.0-preview.19" />
</ItemGroup>

</Project>
36 changes: 6 additions & 30 deletions src/Servers/GenHttpServer11/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

var port = (args.Length > 0 && ushort.TryParse(args[0], out var p)) ? p : (ushort)8080;

var rootMethods = new HashSet<RequestMethod> { RequestMethod.Get, RequestMethod.Head, RequestMethod.Options };
var rootMethods = new HashSet<RequestMethod> { RequestMethod.Get, RequestMethod.Head, RequestMethod.Options };

var app = Inline.Create()
.Get("/cookie", (IRequest request) => ParseCookies(request))
Expand All @@ -35,10 +35,7 @@ static string Echo(IRequest request)
{
var header = source[i];

var key = Encoding.ASCII.GetString(header.Key.Span);
var value = Encoding.ASCII.GetString(header.Value.Span);

headers.AppendLine($"{key}: {value}");
headers.AppendLine($"{header.Key}: {header.Value}");
}

return headers.ToString();
Expand All @@ -48,34 +45,13 @@ static string ParseCookies(IRequest request)
{
var sb = new StringBuilder();

var cookieHeader = request.Header.Headers.GetEntry("Cookie");

if (cookieHeader == null)
{
return string.Empty;
}

var remaining = cookieHeader.AsSpan();
var cookies = request.Header.Headers.GetCookies();

while (!remaining.IsEmpty)
for (var i = 0; i < cookies.Count; i++)
{
var delimiterIndex = remaining.IndexOf("; ");

var segment = delimiterIndex >= 0
? remaining[..delimiterIndex]
: remaining;

var equalsIndex = segment.IndexOf('=');

if (equalsIndex > 0)
{
var key = segment[..equalsIndex].Trim();
var value = segment[(equalsIndex + 1)..].Trim();

sb.AppendLine($"{key}: {value}");
}
var cookie = cookies[i];

remaining = delimiterIndex >= 0 ? remaining[(delimiterIndex + 2)..] : ReadOnlySpan<char>.Empty;
sb.AppendLine($"{cookie.Key}: {cookie.Value}");
}

return sb.ToString();
Expand Down
Loading