private static GetResponseHeaderCharBufferLength ( Interop.WinHttp.SafeWinHttpHandle requestHandle, uint infoLevel ) : int | ||
requestHandle | Interop.WinHttp.SafeWinHttpHandle | |
infoLevel | uint | |
return | int |
private unsafe static int GetResponseHeaderCharBufferLength(SafeWinHttpHandle requestHandle, uint infoLevel)
{
char* buffer = null;
int bufferLength = 0;
uint index = 0;
if (!QueryHeaders(requestHandle, infoLevel, buffer, ref bufferLength, ref index))
{
int lastError = Marshal.GetLastWin32Error();
Debug.Assert(lastError != Interop.WinHttp.ERROR_WINHTTP_HEADER_NOT_FOUND);
if (lastError != Interop.WinHttp.ERROR_INSUFFICIENT_BUFFER)
{
throw WinHttpException.CreateExceptionUsingError(lastError);
}
}
return bufferLength;
}
private void ReadResponseTrailers() { // Only load response trailers if: // 1. WINHTTP_QUERY_FLAG_TRAILERS is supported by the OS // 2. HTTP/2 or later (WINHTTP_QUERY_FLAG_TRAILERS does not work with HTTP/1.1) // 3. Response trailers not already loaded if (!WinHttpTrailersHelper.OsSupportsTrailers || _responseMessage.Version < WinHttpHandler.HttpVersion20 || _readTrailingHeaders) { return; } _readTrailingHeaders = true; var bufferLength = WinHttpResponseParser.GetResponseHeaderCharBufferLength(_requestHandle, isTrailingHeaders: true); if (bufferLength != 0) { char[] trailersBuffer = ArrayPool <char> .Shared.Rent(bufferLength); try { WinHttpResponseParser.ParseResponseTrailers(_requestHandle, _responseMessage, trailersBuffer); } finally { ArrayPool <char> .Shared.Return(trailersBuffer); } } }