Skip to content

Commit a7d5c72

Browse files
Merge pull request #11 from webexpress-framework/copilot/update-readme-documentation
Fix PR #10 review comments: null safety, interface visibility, cookie parsing, WebSocket headers, typos
2 parents f068d0c + 61d52b2 commit a7d5c72

15 files changed

Lines changed: 52 additions & 41 deletions

src/WebExpress.WebCore.Test/Html/UnitTestRandomId.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void HexCharacters()
5959
var id = RandomId.Create();
6060

6161
// validation
62-
var hex = id.Substring(4);
62+
var hex = id.Substring("id_".Length);
6363
Assert.Matches("^[0-9A-F]+$", hex);
6464
}
6565

src/WebExpress.WebCore.Test/Manager/UnitTestStatusPageManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ public void CreateAndCheckCode(Type applicationType, int statusCode, int? expect
165165
/// Test the CreateStatusResponse function of the status page.
166166
/// </summary>
167167
[Theory]
168-
[InlineData(typeof(TestApplicationA), 400, "content", "content", 78)]
169-
[InlineData(typeof(TestApplicationA), 500, "content", "content", 78)]
168+
[InlineData(typeof(TestApplicationA), 400, "content", "content", 72)]
169+
[InlineData(typeof(TestApplicationA), 500, "content", "content", 72)]
170170
public void CreateAndCheckMessage(Type applicationType, int statusCode, string content, string expected, int length)
171171
{
172172
// arrange

src/WebExpress.WebCore/WebAttribute/SegmentRegexAttribute.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ public class SegmentRegexAttribute<TParameter> : Attribute, IEndpointAttribute,
2020
private string Expression { get; set; }
2121

2222
/// <summary>
23-
/// Returns or sets the display string.
23+
/// Returns or sets the tag.
2424
/// </summary>
25-
private string Display { get; set; }
25+
private string Tag { get; set; }
2626

2727
/// <summary>
2828
/// Initializes a new instance of the class.
2929
/// </summary>
3030
/// <param name="expression">The regular expression.</param>
31-
/// <param name="display">The display string.</param>
32-
public SegmentRegexAttribute(string expression, string display = null)
31+
/// <param name="tag">The tag.</param>
32+
public SegmentRegexAttribute(string expression, string tag = null)
3333
{
3434
Expression = expression;
35-
Display = display;
35+
Tag = tag;
3636
}
3737

3838
/// <summary>
@@ -41,7 +41,7 @@ public SegmentRegexAttribute(string expression, string display = null)
4141
/// <returns>The path segment.</returns>
4242
public IUriPathSegment ToPathSegment()
4343
{
44-
return new UriPathSegmentVariableRegex<TParameter>(Expression, Display);
44+
return new UriPathSegmentVariableRegex<TParameter>(Expression, Tag);
4545
}
4646
}
4747
}

src/WebExpress.WebCore/WebAttribute/SegmentStringAttribute.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ public class SegmentStringAttribute<TParameter> : Attribute, IEndpointAttribute,
1515
where TParameter : IParameterStatic, new()
1616
{
1717
/// <summary>
18-
/// Returns or sets the display string.
18+
/// Returns or sets the tag.
1919
/// </summary>
20-
private string Display { get; set; }
20+
private string Tag { get; set; }
2121

2222
/// <summary>
2323
/// Initializes a new instance of the class.
2424
/// </summary>
25-
/// <param name="display">The display string.</param>
26-
public SegmentStringAttribute(string display = null)
25+
/// <param name="tag">The tag.</param>
26+
public SegmentStringAttribute(string tag = null)
2727
{
28-
Display = display;
28+
Tag = tag;
2929
}
3030

3131
/// <summary>
@@ -34,7 +34,7 @@ public SegmentStringAttribute(string display = null)
3434
/// <returns>The path segment.</returns>
3535
public IUriPathSegment ToPathSegment()
3636
{
37-
return new UriPathSegmentVariableString<TParameter>(Display);
37+
return new UriPathSegmentVariableString<TParameter>(Tag);
3838
}
3939
}
4040
}

src/WebExpress.WebCore/WebAttribute/SegmentUIntAttribute.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ public class SegmentUIntAttribute<TParameter> : Attribute, IEndpointAttribute, I
1818
where TParameter : IParameterStatic, new()
1919
{
2020
/// <summary>
21-
/// Returns or sets the display string.
21+
/// Returns or sets the tag.
2222
/// </summary>
23-
private string Display { get; set; }
23+
private string Tag { get; set; }
2424

2525
/// <summary>
2626
/// Initializes a new instance of the class.
2727
/// </summary>
28-
/// <param name="display">The display string.</param>
29-
public SegmentUIntAttribute(string display = null)
28+
/// <param name="tag">The tag.</param>
29+
public SegmentUIntAttribute(string tag = null)
3030
{
31-
Display = display;
31+
Tag = tag;
3232
}
3333

3434
/// <summary>
@@ -37,7 +37,7 @@ public SegmentUIntAttribute(string display = null)
3737
/// <returns>The path segment.</returns>
3838
public IUriPathSegment ToPathSegment()
3939
{
40-
return new UriPathSegmentVariableUInt<TParameter>(Display);
40+
return new UriPathSegmentVariableUInt<TParameter>(Tag);
4141
}
4242
}
4343
}

src/WebExpress.WebCore/WebMessage/RequestHeaderFields.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ internal RequestHeaderFields(IFeatureCollection contextFeatures)
124124
SecWebSocketVersion = requestFeature.Headers.SecWebSocketVersion;
125125

126126
Cookies = requestFeature.Headers.Cookie
127+
.SelectMany(c => c.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
127128
.Select(c =>
128129
{
129-
var split = c.Split('=');
130-
return new Cookie(split[0], split[1]);
131-
});
130+
var eqIndex = c.IndexOf('=');
131+
if (eqIndex < 0) { return null; }
132+
return new Cookie(c[..eqIndex].Trim(), c[(eqIndex + 1)..].Trim());
133+
})
134+
.Where(c => c != null);
132135

133136
Authorization = RequestAuthorization.Parse(requestFeature.Headers.Authorization);
134137
}

src/WebExpress.WebCore/WebMessage/ResponseHeaderFields.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ public override string ToString()
142142
sb.AppendLine("Connection: Upgrade");
143143
}
144144

145+
if (!string.IsNullOrWhiteSpace(SecWebSocketAccept))
146+
{
147+
sb.AppendLine("Sec-WebSocket-Accept: " + SecWebSocketAccept);
148+
}
149+
145150
foreach (var c in CustomHeader)
146151
{
147152
sb.AppendLine(c.Key + ": " + c.Value);

src/WebExpress.WebCore/WebSocket/ISockt.cs renamed to src/WebExpress.WebCore/WebSocket/ISocket.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ public interface ISocket : IEndpoint, IDisposable
1111
{
1212
/// <summary>
1313
/// Invoked after the websocket handshake has been accepted.
14-
/// Implementers may use the optional cancellation token to abort long-running startup tasks.
15-
/// the optional connectMessage provides initial metadata from the client (may be null).
1614
/// </summary>
1715
/// <param name="socketConnection">The socket connection.</param>
1816
/// <returns>An asynchronous task.</returns>

src/WebExpress.WebCore/WebSocket/ISocketContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface ISocketContext : IEndpointContext
2525
/// Returns the maximum allowed message size in bytes, or null when the endpoint imposes no limit.
2626
/// servers and hosts may use this to protect against excessively large frames.
2727
/// </summary>
28-
ulong MaxMessageSize { get; }
28+
ulong? MaxMessageSize { get; }
2929

3030
/// <summary>
3131
/// Indicates whether this websocket endpoint requires an authenticated client.

src/WebExpress.WebCore/WebSocket/Model/SocketItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal class SocketItem : IDisposable
5050
/// Returns the maximum allowed message size in bytes, or null when the endpoint imposes no limit.
5151
/// servers and hosts may use this to protect against excessively large frames.
5252
/// </summary>
53-
public ulong MaxMessageSize { get; set; }
53+
public ulong? MaxMessageSize { get; set; }
5454

5555
/// <summary>
5656
/// Returns the conditions that must be met for the resource to be active.

0 commit comments

Comments
 (0)