-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Description
Not sure if this Project is dead or just Feature complete.
Anyway there seems to be a bug in this method.
If the server immediately sends a message to the client after the handshake this method reads to much and "throws away" what it read, which seema to cause lost packages on the receiving end.
public static async Task<string> ReadHttpHeaderAsync(Stream stream, CancellationToken token)
{
int length = 1024*16; // 16KB buffer more than enough for http header
byte[] buffer = new byte[length];
int offset = 0;
int bytesRead = 0;
do
{
if (offset >= length)
{
throw new EntityTooLargeException("Http header message too large to fit in buffer (16KB)");
}
bytesRead = await stream.ReadAsync(buffer, offset, length - offset, token);
offset += bytesRead;
string header = Encoding.UTF8.GetString(buffer, 0, offset);
// as per http specification, all headers should end this this
if (header.Contains("\r\n\r\n"))
{
return header;
}
} while (bytesRead > 0);
return string.Empty;
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels