Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/WebExpress.WebCore.Test/Html/UnitTestRandomId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void HexCharacters()
var id = RandomId.Create();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ public void CreateAndCheckCode(Type applicationType, int statusCode, int? expect
/// Test the CreateStatusResponse function of the status page.
/// </summary>
[Theory]
[InlineData(typeof(TestApplicationA), 400, "content", "content", 78)]
[InlineData(typeof(TestApplicationA), 500, "content", "content", 78)]
[InlineData(typeof(TestApplicationA), 400, "content", "content", 72)]
[InlineData(typeof(TestApplicationA), 500, "content", "content", 72)]
public void CreateAndCheckMessage(Type applicationType, int statusCode, string content, string expected, int length)
{
// arrange
Expand Down
12 changes: 6 additions & 6 deletions src/WebExpress.WebCore/WebAttribute/SegmentRegexAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ public class SegmentRegexAttribute<TParameter> : Attribute, IEndpointAttribute,
private string Expression { get; set; }

/// <summary>
/// Returns or sets the display string.
/// Returns or sets the tag.
/// </summary>
private string Display { get; set; }
private string Tag { get; set; }

/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="expression">The regular expression.</param>
/// <param name="display">The display string.</param>
public SegmentRegexAttribute(string expression, string display = null)
/// <param name="tag">The tag.</param>
public SegmentRegexAttribute(string expression, string tag = null)
{
Expression = expression;
Display = display;
Tag = tag;
}

/// <summary>
Expand All @@ -41,7 +41,7 @@ public SegmentRegexAttribute(string expression, string display = null)
/// <returns>The path segment.</returns>
public IUriPathSegment ToPathSegment()
{
return new UriPathSegmentVariableRegex<TParameter>(Expression, Display);
return new UriPathSegmentVariableRegex<TParameter>(Expression, Tag);
}
}
}
12 changes: 6 additions & 6 deletions src/WebExpress.WebCore/WebAttribute/SegmentStringAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public class SegmentStringAttribute<TParameter> : Attribute, IEndpointAttribute,
where TParameter : IParameterStatic, new()
{
/// <summary>
/// Returns or sets the display string.
/// Returns or sets the tag.
/// </summary>
private string Display { get; set; }
private string Tag { get; set; }

/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="display">The display string.</param>
public SegmentStringAttribute(string display = null)
/// <param name="tag">The tag.</param>
public SegmentStringAttribute(string tag = null)
{
Display = display;
Tag = tag;
}

/// <summary>
Expand All @@ -34,7 +34,7 @@ public SegmentStringAttribute(string display = null)
/// <returns>The path segment.</returns>
public IUriPathSegment ToPathSegment()
{
return new UriPathSegmentVariableString<TParameter>(Display);
return new UriPathSegmentVariableString<TParameter>(Tag);
}
}
}
12 changes: 6 additions & 6 deletions src/WebExpress.WebCore/WebAttribute/SegmentUIntAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ public class SegmentUIntAttribute<TParameter> : Attribute, IEndpointAttribute, I
where TParameter : IParameterStatic, new()
{
/// <summary>
/// Returns or sets the display string.
/// Returns or sets the tag.
/// </summary>
private string Display { get; set; }
private string Tag { get; set; }

/// <summary>
/// Initializes a new instance of the class.
/// </summary>
/// <param name="display">The display string.</param>
public SegmentUIntAttribute(string display = null)
/// <param name="tag">The tag.</param>
public SegmentUIntAttribute(string tag = null)
{
Display = display;
Tag = tag;
}

/// <summary>
Expand All @@ -37,7 +37,7 @@ public SegmentUIntAttribute(string display = null)
/// <returns>The path segment.</returns>
public IUriPathSegment ToPathSegment()
{
return new UriPathSegmentVariableUInt<TParameter>(Display);
return new UriPathSegmentVariableUInt<TParameter>(Tag);
}
}
}
9 changes: 6 additions & 3 deletions src/WebExpress.WebCore/WebMessage/RequestHeaderFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ internal RequestHeaderFields(IFeatureCollection contextFeatures)
SecWebSocketVersion = requestFeature.Headers.SecWebSocketVersion;

Cookies = requestFeature.Headers.Cookie
.SelectMany(c => c.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
.Select(c =>
{
var split = c.Split('=');
return new Cookie(split[0], split[1]);
});
var eqIndex = c.IndexOf('=');
if (eqIndex < 0) { return null; }
return new Cookie(c[..eqIndex].Trim(), c[(eqIndex + 1)..].Trim());
})
.Where(c => c != null);

Authorization = RequestAuthorization.Parse(requestFeature.Headers.Authorization);
}
Expand Down
5 changes: 5 additions & 0 deletions src/WebExpress.WebCore/WebMessage/ResponseHeaderFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public override string ToString()
sb.AppendLine("Connection: Upgrade");
}

if (!string.IsNullOrWhiteSpace(SecWebSocketAccept))
{
sb.AppendLine("Sec-WebSocket-Accept: " + SecWebSocketAccept);
}

foreach (var c in CustomHeader)
{
sb.AppendLine(c.Key + ": " + c.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public interface ISocket : IEndpoint, IDisposable
{
/// <summary>
/// Invoked after the websocket handshake has been accepted.
/// Implementers may use the optional cancellation token to abort long-running startup tasks.
/// the optional connectMessage provides initial metadata from the client (may be null).
/// </summary>
/// <param name="socketConnection">The socket connection.</param>
/// <returns>An asynchronous task.</returns>
Expand Down
2 changes: 1 addition & 1 deletion src/WebExpress.WebCore/WebSocket/ISocketContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface ISocketContext : IEndpointContext
/// Returns the maximum allowed message size in bytes, or null when the endpoint imposes no limit.
/// servers and hosts may use this to protect against excessively large frames.
/// </summary>
ulong MaxMessageSize { get; }
ulong? MaxMessageSize { get; }

/// <summary>
/// Indicates whether this websocket endpoint requires an authenticated client.
Expand Down
2 changes: 1 addition & 1 deletion src/WebExpress.WebCore/WebSocket/Model/SocketItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class SocketItem : IDisposable
/// Returns the maximum allowed message size in bytes, or null when the endpoint imposes no limit.
/// servers and hosts may use this to protect against excessively large frames.
/// </summary>
public ulong MaxMessageSize { get; set; }
public ulong? MaxMessageSize { get; set; }

/// <summary>
/// Returns the conditions that must be met for the resource to be active.
Expand Down
2 changes: 1 addition & 1 deletion src/WebExpress.WebCore/WebSocket/SocketContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class SocketContext : ISocketContext
/// <summary>
/// Maximum allowed message size in bytes, or null when no limit is imposed.
/// </summary>
public ulong MaxMessageSize { get; set; }
public ulong? MaxMessageSize { get; set; }

/// <summary>
/// Indicates whether this websocket endpoint requires an authenticated client.
Expand Down
4 changes: 2 additions & 2 deletions src/WebExpress.WebCore/WebSocket/SocketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private void Register(IPluginContext pluginContext, IEnumerable<IApplicationCont
var cache = false;
var subProtocol = "";
var messageType = SocketMessageType.Text;
var maxMessageSize = ulong.MinValue;
var maxMessageSize = (ulong?)null;
var attributes = socketType.CustomAttributes
.Where(x => !x.AttributeType.GetInterfaces().Contains(typeof(IEndpointAttribute)));

Expand Down Expand Up @@ -376,7 +376,7 @@ var attribute in socketType
// MAX MESSAGE SIZE
if (attributeType == typeof(MaxMessageSizeAttribute))
{
maxMessageSize = (attribute as MaxMessageSizeAttribute)?.MaxMessageSize ?? 0;
maxMessageSize = (attribute as MaxMessageSizeAttribute)?.MaxMessageSize;
continue;
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/WebExpress.WebCore/WebTask/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ITask CreateTask(string id, params object[] args)
{
var key = id?.ToLower();

if (_dictionary.TryGetValue(id, out var value))
if (_dictionary.TryGetValue(key, out var value))
{
return value;
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public ITask CreateTask<TTask>(string id, EventHandler<TaskEventArgs> handler, p
{
var key = id?.ToLower();

if (_dictionary.TryGetValue(id, out var value))
if (_dictionary.TryGetValue(key, out var value))
{
return value;
}
Expand All @@ -141,7 +141,12 @@ public ITask CreateTask<TTask>(string id, EventHandler<TaskEventArgs> handler, p
/// <param name="task">The task.</param>
public void RemoveTask(ITask task)
{
var key = task?.Id.ToLower();
if (task?.Id is null)
{
return;
}

var key = task.Id.ToLower();

if (_dictionary.TryGetValue(key, out var storedTask) && storedTask is Task t)
{
Expand Down
6 changes: 3 additions & 3 deletions src/WebExpress.WebCore/WebUri/IUriPathSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface IUriPathSegment
/// <summary>
/// Returns or sets the id.
/// </summary>
internal string Id { get; }
string Id { get; }

/// <summary>
/// Returns the value.
Expand All @@ -32,12 +32,12 @@ public interface IUriPathSegment
/// This property can be used to determine if the item should be displayed in user
/// interfaces or lists.
/// </remarks>
bool IsHidden { get; internal set; }
bool IsHidden { get; set; }

/// <summary>
/// Returns the URI to which the user is redirected.
/// </summary>
IUri Uri { get; internal set; }
IUri Uri { get; set; }

/// <summary>
/// Checks whether the node matches the path element.
Expand Down
8 changes: 4 additions & 4 deletions src/WebExpress.WebCore/WebUri/UriQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public override string ToString()
/// <summary>
/// Represents a key-value pair used as a query parameter in a URI.
/// </summary>
/// <typeparam name="TParamerer">
/// <typeparam name="TParameter">
/// The type that implements the IParameterStatic interface and defines the structure
/// of the query parameter.
/// </typeparam>
public class UriQuery<TParamerer> : IUriQuery
where TParamerer : IParameterStatic
public class UriQuery<TParameter> : IUriQuery
where TParameter : IParameterStatic
{
/// <summary>
/// Returns the key.
Expand All @@ -64,7 +64,7 @@ public class UriQuery<TParamerer> : IUriQuery
/// <param name="value">The value.</param>
public UriQuery(string value = null)
{
Key = TParamerer.Key;
Key = TParameter.Key;
Value = value;
}

Expand Down