http: nitpicks
This commit is contained in:
parent
ce8ccdae1b
commit
a23a7b8516
3 changed files with 9 additions and 16 deletions
|
@ -24,7 +24,7 @@ public struct HttpContent
|
|||
public byte[] Content;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the contents to a UTF8 string.
|
||||
/// Converts the contents to a UTF-8 string.
|
||||
/// </summary>
|
||||
public string AsText => Encoding.UTF8.GetString(Content);
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public record HttpFields
|
|||
/// <summary>
|
||||
/// Extra fields to include.
|
||||
/// </summary>
|
||||
public Dictionary<string, string>? Misc;
|
||||
public readonly Dictionary<string, string> Misc = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// 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<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
Misc[key] = value;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()));
|
||||
|
|
Loading…
Reference in a new issue