Skip to content

Commit 4c72050

Browse files
committed
dump v1.6
1 parent 002d0e3 commit 4c72050

File tree

11 files changed

+85
-9
lines changed

11 files changed

+85
-9
lines changed

cadente/Sisk.Cadente.CoreEngine/Sisk.Cadente.CoreEngine.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<PropertyGroup>
4848
<AssemblyVersion>1.6.0</AssemblyVersion>
4949
<FileVersion>1.6.0</FileVersion>
50-
<Version>1.6.0-beta8</Version>
50+
<Version>1.6.0-beta9</Version>
5151
</PropertyGroup>
5252

5353
<!-- licensing, readme, signing -->

cadente/Sisk.Cadente/HttpSerializer/HttpRequestReader.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ static class HttpRequestReader {
6060
Logger.LogInformation ( $"failed to parse HTTP request: connection closed" );
6161
return null;
6262
}
63-
if (bytesRead == 0) {
64-
// Connection closed by client before sending complete headers
65-
return null;
66-
}
6763

6864
totalRead += bytesRead;
6965

cadente/Sisk.Cadente/Logger.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ static class Logger {
1717
[Conditional ( "DEBUG" )]
1818
[MethodImpl ( MethodImplOptions.AggressiveInlining )]
1919
public static void LogInformation ( ref DefaultInterpolatedStringHandler message ) {
20+
#if DEBUG
2021
// Note: Connection ID logging is only available in DEBUG builds and may be uninitialized.
21-
var connectionId = HttpConnection.Id.Value != 0 ? HttpConnection.Id.Value.ToString() : "N/A";
22+
var connectionId = HttpConnection.Id.Value != 0 ? HttpConnection.Id.Value.ToString () : "N/A";
2223
Console.WriteLine ( $"Sisk.ManagedHttpListener [{DateTime.Now:R}] [CON {connectionId}] {message.ToString ()}" );
24+
#endif
2325
}
2426
}

cadente/Sisk.Cadente/Sisk.Cadente.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<PropertyGroup>
4848
<AssemblyVersion>1.0</AssemblyVersion>
4949
<FileVersion>1.0</FileVersion>
50-
<Version>1.0-beta8</Version>
50+
<Version>1.0-beta9</Version>
5151
</PropertyGroup>
5252

5353
<!-- licensing, readme, signing -->

cadente/benchmark/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Sisk.Cadente;
2+
3+
var host = new HttpHost ( 5555 ) {
4+
UsePipelines = false // Disable pipelines for testing
5+
};
6+
7+
host.UseHandler ( async ctx => {
8+
ctx.Response.StatusCode = 200;
9+
ctx.Response.Headers.Set ( new HttpHeader ( "Content-Length", "13" ) );
10+
using var stream = await ctx.Response.GetResponseStreamAsync ( chunked: false );
11+
await stream.WriteAsync ( "Hello, World!"u8.ToArray () );
12+
} );
13+
14+
host.Start ();
15+
Console.WriteLine ( $"Server listening on http://localhost:5555" );
16+
Console.WriteLine ( "Press Ctrl+C to stop..." );
17+
Thread.Sleep ( -1 );

cadente/benchmark/benchmark.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\Sisk.Cadente\Sisk.Cadente.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

src/Helpers/PathHelper.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,30 @@ namespace Sisk.Core.Helpers;
1515
/// Provides useful path-dedicated helper members.
1616
/// </summary>
1717
public sealed class PathHelper {
18+
19+
static readonly char [] forbiddenPathChars = Path.GetInvalidPathChars ();
20+
static readonly char [] forbiddenFileChars = Path.GetInvalidFileNameChars ();
21+
22+
/// <summary>
23+
/// Determines whether the specified path contains only valid path and file-name characters.
24+
/// </summary>
25+
/// <param name="path">The path to validate.</param>
26+
/// <returns>
27+
/// <see langword="true"/> if <paramref name="path"/> contains no invalid path or file-name characters;
28+
/// otherwise, <see langword="false"/>.
29+
/// </returns>
30+
public static bool IsPathAllowed ( string path ) {
31+
string filePart = Path.GetFileName ( path );
32+
33+
if (filePart.IndexOfAny ( forbiddenFileChars ) >= 0)
34+
return false;
35+
36+
if (path.IndexOfAny ( forbiddenPathChars ) >= 0)
37+
return false;
38+
39+
return true;
40+
}
41+
1842
/// <summary>
1943
/// Splits the specified path into its individual segments, removing empty entries and trimming whitespace.
2044
/// </summary>

src/Http/BrotliContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// The Sisk Framework source code
1+
// The Sisk Framework source code
22
// Copyright (c) 2024- PROJECT PRINCIPIUM and all Sisk contributors
33
//
44
// The code below is licensed under the MIT license as

src/Http/LogStream.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
// File name: LogStream.cs
88
// Repository: https://github.com/sisk-http/core
99

10+
using System.Globalization;
1011
using System.Text;
1112
using System.Threading.Channels;
1213
using Sisk.Core.Entity;
14+
using Sisk.Core.Helpers;
1315

1416
namespace Sisk.Core.Http {
1517
/// <summary>
@@ -37,6 +39,22 @@ public class LogStream : IDisposable, IAsyncDisposable {
3739
private static readonly Lazy<LogStream> _consoleOutputLazy = new Lazy<LogStream> ( () => new LogStream ( Console.Out ) );
3840
private static readonly Lazy<LogStream> _emptyLazy = new Lazy<LogStream> ( () => new LogStream () );
3941

42+
/// <summary>
43+
/// Converts the specified <see cref="DateTime"/> to a file-name-safe string representation
44+
/// formatted as "yyyy-MM-dd_HH-mm-ss".
45+
/// </summary>
46+
/// <param name="dt">The date and time to convert.</param>
47+
/// <param name="provider">An object that supplies culture-specific formatting information. Can be <see langword="null"/>.</param>
48+
/// <returns>A string that is safe for use in file names.</returns>
49+
public static string EscapeSafeDateTime ( DateTime dt, IFormatProvider? provider = null ) {
50+
return dt.ToString ( "yyyy-MM-dd_HH-mm-ss", provider );
51+
}
52+
53+
/// <summary>
54+
/// Gets the current local date and time as a file-name-safe string formatted as "yyyy-MM-dd_HH-mm-ss".
55+
/// </summary>
56+
public static string SafeTimestamp => EscapeSafeDateTime ( DateTime.Now, CultureInfo.InvariantCulture );
57+
4058
/// <summary>
4159
/// Gets a shared <see cref="LogStream"/> that writes its output to the <see cref="Console.Out"/> stream.
4260
/// </summary>
@@ -86,6 +104,10 @@ public string? FilePath {
86104
if (value is not null) {
87105
_filePath = Path.GetFullPath ( value );
88106

107+
if (!PathHelper.IsPathAllowed ( _filePath )) {
108+
throw new ArgumentException ( SR.Format ( SR.LogStream_InvalidFilePath, value ), nameof ( value ) );
109+
}
110+
89111
string? dirPath = Path.GetDirectoryName ( _filePath );
90112
if (dirPath is not null)
91113
Directory.CreateDirectory ( dirPath );

src/Internal/SR.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static partial class SR {
6464
public const string LogStream_RotatingLogPolicy_NotLocalFile = "Cannot link an rotaging log policy to an log stream which ins't pointing to an local file.";
6565
public const string LogStream_RotatingLogPolicy_AlreadyBind = "The specified LogStream is already binded to another RotatingLogPolicy.";
6666
public const string LogStream_RotatingLogPolicy_IntervalZero = "The RotatingLogPolicy interval must be greater than zero.";
67+
public const string LogStream_InvalidFilePath = "Invalid file path specified for the LogStream: '{0}'";
6768

6869
public const string HttpRequestEventSource_KeepAliveDisposed = "Cannot keep alive an instance that has it's connection disposed.";
6970

0 commit comments

Comments
 (0)