Skip to content

Commit

Permalink
HTTP/3: Fix decoding trailing headers (#46734)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK authored Jan 8, 2021
1 parent c40ef74 commit 97d11fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,21 @@ public void Dispose()
}
}

/// <summary>
/// Reset the decoder state back to its initial value. Resetting state is required when reusing a decoder with multiple
/// header frames. For example, decoding a response's headers and trailers.
/// </summary>
public void Reset()
{
_state = State.RequiredInsertCount;
}

public void Decode(in ReadOnlySequence<byte> headerBlock, IHttpHeadersHandler handler)
{
foreach (ReadOnlyMemory<byte> segment in headerBlock)
{
Decode(segment.Span, handler);
}

_state = State.RequiredInsertCount;
}

public void Decode(ReadOnlySpan<byte> headerBlock, IHttpHeadersHandler handler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,9 @@ private async ValueTask ReadHeadersAsync(long headersLength, CancellationToken c
_recvBuffer.Discard(processLength);
headersLength -= processLength;
}

// Reset decoder state. Require because one decoder instance is reused to decode headers and trailers.
_headerDecoder.Reset();
}

private static ReadOnlySpan<byte> StatusHeaderNameBytes => new byte[] { (byte)'s', (byte)'t', (byte)'a', (byte)'t', (byte)'u', (byte)'s' };
Expand Down

0 comments on commit 97d11fb

Please sign in to comment.