Skip to content

Commit

Permalink
Updated fix issue with Http client timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickRitchie committed Oct 5, 2022
1 parent 955fcf9 commit 9dbdbed
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/MTConnect.NET-HTTP/Clients/Rest/MTConnectHttpClientStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ public async Task Run(CancellationToken cancellationToken)
var contentLength = 0;
string contentEncoding = null;
var trimBytes = new byte[] { 10, 13 };
string lineStr = null;

var b = stream.ReadByte();
var readBuffer = new byte[1];
await stream.ReadAsync(readBuffer, 0, readBuffer.Length, stop.Token);
int b = readBuffer[0];

if (Timeout > 0)
{
Expand All @@ -192,15 +195,15 @@ public async Task Run(CancellationToken cancellationToken)
if (cr && lf)
{
// Trim CR and LF bytes from beginning and end
var lineBytes = ObjectExtensions.TrimBytes(line.ToArray(), trimBytes);
//var lineBytes = ObjectExtensions.TrimBytes(line.ToArray(), trimBytes);

// Get the current line as a UTF-8 string
var lineStr = Encoding.UTF8.GetString(lineBytes);
lineStr = Encoding.UTF8.GetString(line.ToArray());

if (headerActive)
{
// Add Header
header.AddRange(lineBytes);
header.AddRange(line.ToArray());

if (prevNewLine)
{
Expand Down Expand Up @@ -244,7 +247,8 @@ public async Task Run(CancellationToken cancellationToken)
prevByte = b;

// Read the next Byte
b = stream.ReadByte();
await stream.ReadAsync(readBuffer, 0, readBuffer.Length, stop.Token);
b = readBuffer[0];

if (Timeout > 0)
{
Expand Down

0 comments on commit 9dbdbed

Please sign in to comment.