diff --git a/HTTP/HttpContent.cs b/HTTP/HttpContent.cs index daff290..0b8ad28 100644 --- a/HTTP/HttpContent.cs +++ b/HTTP/HttpContent.cs @@ -24,7 +24,7 @@ public struct HttpContent public byte[] Content; /// - /// Converts the contents to a UTF8 string. + /// Converts the contents to a UTF-8 string. /// public string AsText => Encoding.UTF8.GetString(Content); diff --git a/HTTP/HttpFields.cs b/HTTP/HttpFields.cs index 8b5526a..b6747a6 100644 --- a/HTTP/HttpFields.cs +++ b/HTTP/HttpFields.cs @@ -32,7 +32,7 @@ public record HttpFields /// /// Extra fields to include. /// - public Dictionary? Misc; + public readonly Dictionary Misc = new Dictionary(StringComparer.OrdinalIgnoreCase); /// /// Sets a field. The string will be parsed for non-string fields like Accept. @@ -107,14 +107,9 @@ public record HttpFields default: if (value == null) - { Misc?.Remove(key); - } else - { - Misc ??= new Dictionary(StringComparer.OrdinalIgnoreCase); Misc[key] = value; - } return; } } diff --git a/HTTP/HttpResponse.cs b/HTTP/HttpResponse.cs index 17d6a14..6145eea 100644 --- a/HTTP/HttpResponse.cs +++ b/HTTP/HttpResponse.cs @@ -80,14 +80,6 @@ public class HttpResponse StringBuilder sb = new StringBuilder(); - void writeField(string name, string value) - { - sb.Append(name); - sb.Append(": "); - sb.Append(value); - sb.Append("\r\n"); - } - sb.Append("HTTP/1.1 "); sb.Append(StatusCode); sb.Append(' '); @@ -105,7 +97,13 @@ public class HttpResponse Fields.ContentType = null; } - Fields.EmitAll(writeField); + Fields.EmitAll((string name, string value) => + { + sb.Append(name); + sb.Append(": "); + sb.Append(value); + sb.Append("\r\n"); + }); sb.Append("\r\n"); await stream.Write(Encoding.ASCII.GetBytes(sb.ToString()));