| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.Diagnostics; |
| | | 6 | | using System.Diagnostics.CodeAnalysis; |
| | | 7 | | using System.IO; |
| | | 8 | | using System.Net.Http.Headers; |
| | | 9 | | using System.Net.Http.QPack; |
| | | 10 | | using System.Net.Quic; |
| | | 11 | | using System.Runtime.CompilerServices; |
| | | 12 | | using System.Runtime.ExceptionServices; |
| | | 13 | | using System.Runtime.Versioning; |
| | | 14 | | using System.Text; |
| | | 15 | | using System.Threading; |
| | | 16 | | using System.Threading.Tasks; |
| | | 17 | | |
| | | 18 | | namespace System.Net.Http |
| | | 19 | | { |
| | | 20 | | [SupportedOSPlatform("linux")] |
| | | 21 | | [SupportedOSPlatform("macos")] |
| | | 22 | | [SupportedOSPlatform("windows")] |
| | | 23 | | internal sealed class Http3RequestStream : IHttpStreamHeadersHandler, IAsyncDisposable, IDisposable |
| | | 24 | | { |
| | | 25 | | private readonly HttpRequestMessage _request; |
| | | 26 | | private Http3Connection _connection; |
| | 0 | 27 | | private long _streamId = -1; // A stream does not have an ID until the first I/O against it. This gets set almos |
| | | 28 | | private readonly QuicStream _stream; |
| | | 29 | | private volatile bool _finishingBackgroundWrite; |
| | | 30 | | private ArrayBuffer _sendBuffer; |
| | | 31 | | private volatile bool _finishingBackgroundRead; |
| | | 32 | | private ArrayBuffer _recvBuffer; |
| | | 33 | | private TaskCompletionSource<bool>? _expect100ContinueCompletionSource; // True indicates we should send content |
| | | 34 | | private bool _disposed; |
| | | 35 | | private readonly CancellationTokenSource _requestBodyCancellationSource; |
| | | 36 | | |
| | | 37 | | // Allocated when we receive a :status header. |
| | | 38 | | private HttpResponseMessage? _response; |
| | | 39 | | |
| | | 40 | | // Header decoding. |
| | | 41 | | private readonly QPackDecoder _headerDecoder; |
| | | 42 | | private HeaderState _headerState; |
| | | 43 | | private int _headerBudgetRemaining; |
| | | 44 | | |
| | | 45 | | /// <summary>Reusable array used to get the values for each header being written to the wire.</summary> |
| | 0 | 46 | | private string[] _headerValues = Array.Empty<string>(); |
| | | 47 | | |
| | | 48 | | /// <summary>Any trailing headers.</summary> |
| | | 49 | | private HttpResponseHeaders? _trailingHeaders; |
| | | 50 | | |
| | | 51 | | // When reading response content, keep track of the number of bytes left in the current data frame. |
| | | 52 | | private long _responseDataPayloadRemaining; |
| | | 53 | | |
| | | 54 | | // When our request content has a precomputed length, it is sent over a single DATA frame. |
| | | 55 | | // Keep track of how much is remaining in that frame. |
| | | 56 | | private long _requestContentLengthRemaining; |
| | | 57 | | |
| | | 58 | | // For the precomputed length case, we need to add the DATA framing for the first write only. |
| | | 59 | | private bool _singleDataFrameWritten; |
| | | 60 | | |
| | | 61 | | private bool _requestSendCompleted; |
| | | 62 | | private bool _responseRecvCompleted; |
| | | 63 | | |
| | | 64 | | public long StreamId |
| | | 65 | | { |
| | 0 | 66 | | get => Volatile.Read(ref _streamId); |
| | 0 | 67 | | set => Volatile.Write(ref _streamId, value); |
| | | 68 | | } |
| | | 69 | | |
| | 0 | 70 | | public Http3RequestStream(HttpRequestMessage request, Http3Connection connection, QuicStream stream) |
| | 0 | 71 | | { |
| | 0 | 72 | | _request = request; |
| | 0 | 73 | | _connection = connection; |
| | 0 | 74 | | _stream = stream; |
| | 0 | 75 | | _sendBuffer = new ArrayBuffer(initialSize: 64, usePool: true); |
| | 0 | 76 | | _recvBuffer = new ArrayBuffer(initialSize: 64, usePool: true); |
| | | 77 | | |
| | 0 | 78 | | _headerBudgetRemaining = connection.Pool.Settings.MaxResponseHeadersByteLength; |
| | 0 | 79 | | _headerDecoder = new QPackDecoder(maxHeadersLength: (int)Math.Min(int.MaxValue, _headerBudgetRemaining)); |
| | | 80 | | |
| | 0 | 81 | | _requestBodyCancellationSource = new CancellationTokenSource(); |
| | | 82 | | |
| | 0 | 83 | | _requestSendCompleted = _request.Content == null; |
| | 0 | 84 | | _responseRecvCompleted = false; |
| | 0 | 85 | | } |
| | | 86 | | |
| | | 87 | | public void Dispose() |
| | 0 | 88 | | { |
| | 0 | 89 | | if (!_disposed) |
| | 0 | 90 | | { |
| | 0 | 91 | | _disposed = true; |
| | 0 | 92 | | AbortStream(); |
| | 0 | 93 | | if (_stream.WritesClosed.IsCompleted) |
| | 0 | 94 | | { |
| | 0 | 95 | | _connection.LogExceptions(_stream.DisposeAsync().AsTask()); |
| | 0 | 96 | | } |
| | | 97 | | else |
| | 0 | 98 | | { |
| | 0 | 99 | | _stream.Dispose(); |
| | 0 | 100 | | } |
| | 0 | 101 | | DisposeSyncHelper(); |
| | 0 | 102 | | } |
| | 0 | 103 | | } |
| | | 104 | | |
| | | 105 | | private void RemoveFromConnectionIfDone() |
| | 0 | 106 | | { |
| | 0 | 107 | | if (_responseRecvCompleted && _requestSendCompleted) |
| | 0 | 108 | | { |
| | 0 | 109 | | _connection.RemoveStream(_stream); |
| | 0 | 110 | | } |
| | 0 | 111 | | } |
| | | 112 | | |
| | | 113 | | public async ValueTask DisposeAsync() |
| | 0 | 114 | | { |
| | 0 | 115 | | if (!_disposed) |
| | 0 | 116 | | { |
| | 0 | 117 | | _disposed = true; |
| | 0 | 118 | | AbortStream(); |
| | 0 | 119 | | if (_stream.WritesClosed.IsCompleted) |
| | 0 | 120 | | { |
| | 0 | 121 | | _connection.LogExceptions(_stream.DisposeAsync().AsTask()); |
| | 0 | 122 | | } |
| | | 123 | | else |
| | 0 | 124 | | { |
| | 0 | 125 | | await _stream.DisposeAsync().ConfigureAwait(false); |
| | 0 | 126 | | } |
| | 0 | 127 | | DisposeSyncHelper(); |
| | 0 | 128 | | } |
| | 0 | 129 | | } |
| | | 130 | | |
| | | 131 | | private void DisposeSyncHelper() |
| | 0 | 132 | | { |
| | 0 | 133 | | _connection.RemoveStream(_stream); |
| | | 134 | | |
| | | 135 | | // If the request sending was offloaded to be done concurrently and not awaited within SendAsync (by calling |
| | | 136 | | // the _sendBuffer disposal is the responsibility of that offloaded task to prevent returning the buffer to |
| | 0 | 137 | | if (!_finishingBackgroundWrite) |
| | 0 | 138 | | { |
| | 0 | 139 | | _sendBuffer.Dispose(); |
| | 0 | 140 | | } |
| | | 141 | | // If the response receiving was offloaded to be done concurrently and not awaited within SendAsync (by call |
| | | 142 | | // the _recvBuffer disposal is the responsibility of that offloaded task to prevent returning the buffer to |
| | 0 | 143 | | if (!_finishingBackgroundRead) |
| | 0 | 144 | | { |
| | 0 | 145 | | _recvBuffer.Dispose(); |
| | 0 | 146 | | } |
| | 0 | 147 | | } |
| | | 148 | | |
| | | 149 | | public void GoAway() |
| | 0 | 150 | | { |
| | 0 | 151 | | _requestBodyCancellationSource.Cancel(); |
| | 0 | 152 | | } |
| | | 153 | | |
| | | 154 | | public async Task<HttpResponseMessage> SendAsync(CancellationToken cancellationToken) |
| | 0 | 155 | | { |
| | | 156 | | // If true, dispose the stream upon return. Will be set to false if we're duplex or returning content. |
| | 0 | 157 | | bool disposeSelf = true; |
| | | 158 | | |
| | 0 | 159 | | bool duplex = _request.Content != null && _request.Content.AllowDuplex; |
| | | 160 | | |
| | | 161 | | // Link the input token with _requestBodyCancellationSource, so cancellation will trigger on GoAway() or Abo |
| | 0 | 162 | | CancellationTokenRegistration linkedTokenRegistration = cancellationToken.UnsafeRegister(cts => ((Cancellati |
| | | 163 | | |
| | | 164 | | // upon failure, we should cancel the _requestBodyCancellationSource |
| | 0 | 165 | | bool shouldCancelBody = true; |
| | | 166 | | try |
| | 0 | 167 | | { |
| | 0 | 168 | | BufferHeaders(_request); |
| | | 169 | | |
| | | 170 | | // If using Expect 100 Continue, setup a TCS to wait to send content until we get a response. |
| | 0 | 171 | | if (_request.HasHeaders && _request.Headers.ExpectContinue == true) |
| | 0 | 172 | | { |
| | 0 | 173 | | _expect100ContinueCompletionSource = new TaskCompletionSource<bool>(); |
| | 0 | 174 | | } |
| | | 175 | | |
| | 0 | 176 | | if (_expect100ContinueCompletionSource != null || _request.Content == null) |
| | 0 | 177 | | { |
| | | 178 | | // Ideally, headers will be sent out in a gathered write inside of SendContentAsync(). |
| | | 179 | | // If we don't have content, or we are doing Expect 100 Continue, then we can't rely on |
| | | 180 | | // this and must send our headers immediately. |
| | | 181 | | |
| | | 182 | | // End the stream writing if there's no content to send, do it as part of the write so that the FIN |
| | | 183 | | // Note that there's no need to call Shutdown separately since the FIN flag in the last write is the |
| | 0 | 184 | | await FlushSendBufferAsync(endStream: _request.Content == null, _requestBodyCancellationSource.Token |
| | 0 | 185 | | } |
| | | 186 | | |
| | 0 | 187 | | Task sendRequestTask = _request.Content != null |
| | 0 | 188 | | ? SendContentAsync(_request.Content, _requestBodyCancellationSource.Token) |
| | 0 | 189 | | : Task.CompletedTask; |
| | | 190 | | |
| | | 191 | | // In parallel, send content and read response. |
| | | 192 | | // Depending on Expect 100 Continue usage, one will depend on the other making progress. |
| | 0 | 193 | | Task readResponseTask = ReadResponseAsync(_requestBodyCancellationSource.Token); |
| | 0 | 194 | | bool sendContentObserved = false; |
| | | 195 | | |
| | | 196 | | // If we're not doing duplex, wait for content to finish sending here. |
| | | 197 | | // If we are doing duplex and have the unlikely event that it completes here, observe the result. |
| | | 198 | | // See Http2Connection.SendAsync for a full comment on this logic -- it is identical behavior. |
| | 0 | 199 | | if (sendRequestTask.IsCompleted || |
| | 0 | 200 | | _request.Content?.AllowDuplex != true || |
| | 0 | 201 | | await Task.WhenAny(sendRequestTask, readResponseTask).ConfigureAwait(false) == sendRequestTask || |
| | 0 | 202 | | sendRequestTask.IsCompleted) |
| | 0 | 203 | | { |
| | | 204 | | try |
| | 0 | 205 | | { |
| | 0 | 206 | | await sendRequestTask.ConfigureAwait(false); |
| | 0 | 207 | | sendContentObserved = true; |
| | 0 | 208 | | } |
| | 0 | 209 | | catch |
| | 0 | 210 | | { |
| | | 211 | | // This is a best effort attempt to transfer the responsibility of disposing _recvBuffer to Read |
| | | 212 | | // The task might be past checking the variable or already finished, in which case the buffer wo |
| | | 213 | | // Not returning the buffer to the pool is an acceptable trade-off for making sure that the buff |
| | 0 | 214 | | _finishingBackgroundRead = true; |
| | | 215 | | |
| | | 216 | | // Exceptions will be bubbled up from sendRequestTask here, |
| | | 217 | | // which means the result of readResponseTask won't be observed directly: |
| | | 218 | | // Do a background await to log any exceptions. |
| | 0 | 219 | | _connection.LogExceptions(readResponseTask); |
| | 0 | 220 | | throw; |
| | | 221 | | } |
| | 0 | 222 | | } |
| | | 223 | | else |
| | 0 | 224 | | { |
| | | 225 | | // This is a best effort attempt to transfer the responsibility of disposing _sendBuffer to SendCont |
| | | 226 | | // The task might be past checking the variable or already finished, in which case the buffer won't |
| | | 227 | | // Not returning the buffer to the pool is an acceptable trade-off for making sure that the buffer i |
| | 0 | 228 | | _finishingBackgroundWrite = true; |
| | | 229 | | |
| | | 230 | | // Duplex is being used, so we can't wait for content to finish sending. |
| | | 231 | | // Do a background await to log any exceptions. |
| | 0 | 232 | | _connection.LogExceptions(sendRequestTask); |
| | 0 | 233 | | } |
| | | 234 | | |
| | | 235 | | // Wait for the response headers to be read. |
| | 0 | 236 | | await readResponseTask.ConfigureAwait(false); |
| | | 237 | | |
| | | 238 | | // If we've sent a body, wait for the writes to be closed (most likely already done). |
| | | 239 | | // If sendRequestTask hasn't completed yet, we're doing duplex content transfers and can't wait for writ |
| | 0 | 240 | | if (sendRequestTask.IsCompletedSuccessfully && |
| | 0 | 241 | | _stream.WritesClosed is { IsCompletedSuccessfully: false } writesClosed) |
| | 0 | 242 | | { |
| | | 243 | | try |
| | 0 | 244 | | { |
| | 0 | 245 | | await writesClosed.WaitAsync(_requestBodyCancellationSource.Token).ConfigureAwait(false); |
| | 0 | 246 | | } |
| | 0 | 247 | | catch (QuicException qex) when (qex.QuicError == QuicError.StreamAborted && qex.ApplicationErrorCode |
| | 0 | 248 | | { |
| | | 249 | | // The server doesn't need the whole request to respond so it's aborting its reading side gracef |
| | 0 | 250 | | } |
| | 0 | 251 | | } |
| | | 252 | | |
| | 0 | 253 | | Debug.Assert(_response != null && _response.Content != null); |
| | | 254 | | // Set our content stream. |
| | 0 | 255 | | var responseContent = (HttpConnectionResponseContent)_response.Content; |
| | | 256 | | |
| | | 257 | | // If we have received Content-Length: 0 and have completed sending content (which may not be the case i |
| | | 258 | | // we can close our Http3RequestStream immediately and return a singleton empty content stream. Otherwis |
| | | 259 | | // need to return a Http3ReadStream which will be responsible for disposing the Http3RequestStream. |
| | 0 | 260 | | bool useEmptyResponseContent = responseContent.Headers.ContentLength == 0 && sendContentObserved; |
| | 0 | 261 | | if (useEmptyResponseContent) |
| | 0 | 262 | | { |
| | | 263 | | // Drain the response frames to read any trailing headers. |
| | 0 | 264 | | await DrainContentLength0Frames(_requestBodyCancellationSource.Token).ConfigureAwait(false); |
| | 0 | 265 | | responseContent.SetStream(EmptyReadStream.Instance); |
| | 0 | 266 | | } |
| | | 267 | | else |
| | 0 | 268 | | { |
| | | 269 | | // A read stream is required to finish up the request. |
| | 0 | 270 | | responseContent.SetStream(new Http3ReadStream(this)); |
| | 0 | 271 | | } |
| | 0 | 272 | | if (NetEventSource.Log.IsEnabled()) Trace($"Received response: {_response}"); |
| | | 273 | | |
| | | 274 | | // Process any Set-Cookie headers. |
| | 0 | 275 | | if (_connection.Pool.Settings._useCookies) |
| | 0 | 276 | | { |
| | 0 | 277 | | CookieHelper.ProcessReceivedCookies(_response, _connection.Pool.Settings._cookieContainer!); |
| | 0 | 278 | | } |
| | | 279 | | |
| | | 280 | | // To avoid a circular reference (stream->response->content->stream), null out the stream's response. |
| | 0 | 281 | | HttpResponseMessage response = _response; |
| | 0 | 282 | | _response = null; |
| | | 283 | | |
| | | 284 | | // If we're 100% done with the stream, dispose. |
| | 0 | 285 | | disposeSelf = useEmptyResponseContent; |
| | | 286 | | |
| | | 287 | | // Success, don't cancel the body. |
| | 0 | 288 | | shouldCancelBody = false; |
| | 0 | 289 | | return response; |
| | | 290 | | } |
| | 0 | 291 | | catch (QuicException ex) when (ex.QuicError == QuicError.StreamAborted) |
| | | 292 | | { |
| | | 293 | | Debug.Assert(ex.ApplicationErrorCode.HasValue); |
| | | 294 | | Http3ErrorCode code = (Http3ErrorCode)ex.ApplicationErrorCode.Value; |
| | | 295 | | |
| | | 296 | | switch (code) |
| | | 297 | | { |
| | | 298 | | case Http3ErrorCode.VersionFallback: |
| | | 299 | | // The server is requesting us fall back to an older HTTP version. |
| | | 300 | | throw new HttpRequestException(HttpRequestError.Unknown, SR.net_http_retry_on_older_version, ex, |
| | | 301 | | |
| | | 302 | | case Http3ErrorCode.RequestRejected: |
| | | 303 | | // The server is rejecting the request without processing it, retry it on a different connection |
| | | 304 | | HttpProtocolException rejectedException = HttpProtocolException.CreateHttp3StreamException(code, |
| | | 305 | | throw new HttpRequestException(HttpRequestError.HttpProtocolError, SR.net_http_request_aborted, |
| | | 306 | | |
| | | 307 | | default: |
| | | 308 | | // Our stream was reset. |
| | | 309 | | Exception innerException = _connection.AbortException ?? HttpProtocolException.CreateHttp3Stream |
| | | 310 | | HttpRequestError httpRequestError = innerException is HttpProtocolException ? HttpRequestError.H |
| | | 311 | | throw new HttpRequestException(httpRequestError, SR.net_http_client_execution_error, innerExcept |
| | | 312 | | } |
| | | 313 | | } |
| | 0 | 314 | | catch (QuicException ex) when (ex.QuicError == QuicError.ConnectionAborted) |
| | | 315 | | { |
| | | 316 | | // Our connection was reset. Start shutting down the connection. |
| | | 317 | | Debug.Assert(ex.ApplicationErrorCode.HasValue); |
| | | 318 | | Http3ErrorCode code = (Http3ErrorCode)ex.ApplicationErrorCode.Value; |
| | | 319 | | |
| | | 320 | | Exception abortException = _connection.Abort(HttpProtocolException.CreateHttp3ConnectionException(code, |
| | | 321 | | throw new HttpRequestException(HttpRequestError.HttpProtocolError, SR.net_http_client_execution_error, a |
| | | 322 | | } |
| | 0 | 323 | | catch (QuicException ex) when (ex.QuicError == QuicError.OperationAborted && cancellationToken.IsCancellatio |
| | | 324 | | { |
| | | 325 | | // It is possible for QuicStream's code to throw an |
| | | 326 | | // OperationAborted QuicException when cancellation is requested. |
| | | 327 | | throw new TaskCanceledException(ex.Message, ex, cancellationToken); |
| | | 328 | | } |
| | 0 | 329 | | catch (QuicException ex) when (ex.QuicError == QuicError.OperationAborted && _connection.AbortException != n |
| | | 330 | | { |
| | | 331 | | // we closed the connection already, propagate the AbortException |
| | | 332 | | HttpRequestError httpRequestError = _connection.AbortException is HttpProtocolException |
| | | 333 | | ? HttpRequestError.HttpProtocolError |
| | | 334 | | : HttpRequestError.Unknown; |
| | | 335 | | |
| | | 336 | | throw new HttpRequestException(httpRequestError, SR.net_http_client_execution_error, _connection.AbortEx |
| | | 337 | | } |
| | 0 | 338 | | catch (QuicException ex) |
| | 0 | 339 | | { |
| | | 340 | | // Any other QuicException means transport error, and should be treated as a connection failure. |
| | 0 | 341 | | _connection.Abort(ex); |
| | 0 | 342 | | throw new HttpRequestException(HttpRequestError.Unknown, SR.net_http_http3_connection_quic_error, ex); |
| | | 343 | | } |
| | | 344 | | // It is possible for user's Content code to throw an unexpected OperationCanceledException. |
| | 0 | 345 | | catch (OperationCanceledException ex) when (ex.CancellationToken == _requestBodyCancellationSource.Token || |
| | | 346 | | { |
| | | 347 | | // We're either observing GOAWAY, or the cancellationToken parameter has been canceled. |
| | | 348 | | if (cancellationToken.IsCancellationRequested) |
| | | 349 | | { |
| | | 350 | | _stream.Abort(QuicAbortDirection.Write, (long)Http3ErrorCode.RequestCancelled); |
| | | 351 | | throw new TaskCanceledException(ex.Message, ex, cancellationToken); |
| | | 352 | | } |
| | | 353 | | else |
| | | 354 | | { |
| | | 355 | | Debug.Assert(_requestBodyCancellationSource.IsCancellationRequested); |
| | | 356 | | throw new HttpRequestException(HttpRequestError.Unknown, SR.net_http_request_aborted, ex, RequestRet |
| | | 357 | | } |
| | | 358 | | } |
| | 0 | 359 | | catch (HttpIOException ex) |
| | 0 | 360 | | { |
| | 0 | 361 | | _connection.Abort(ex); |
| | 0 | 362 | | throw new HttpRequestException(ex.HttpRequestError, SR.net_http_client_execution_error, ex); |
| | | 363 | | } |
| | 0 | 364 | | catch (QPackDecodingException ex) |
| | 0 | 365 | | { |
| | 0 | 366 | | Exception abortException = _connection.Abort(HttpProtocolException.CreateHttp3ConnectionException(Http3E |
| | 0 | 367 | | throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.net_http_invalid_response, ex); |
| | | 368 | | } |
| | 0 | 369 | | catch (QPackEncodingException ex) |
| | 0 | 370 | | { |
| | 0 | 371 | | _stream.Abort(QuicAbortDirection.Write, (long)Http3ErrorCode.InternalError); |
| | 0 | 372 | | throw new HttpRequestException(HttpRequestError.Unknown, SR.net_http_client_execution_error, ex); |
| | | 373 | | } |
| | 0 | 374 | | catch (Exception ex) |
| | 0 | 375 | | { |
| | 0 | 376 | | _stream.Abort(QuicAbortDirection.Write, (long)Http3ErrorCode.InternalError); |
| | 0 | 377 | | if (ex is HttpRequestException) |
| | 0 | 378 | | { |
| | 0 | 379 | | throw; |
| | | 380 | | } |
| | | 381 | | |
| | | 382 | | // all exceptions should be already handled above |
| | 0 | 383 | | Debug.Fail($"Unexpected exception type in Http3RequestStream.SendAsync: {ex}"); |
| | | 384 | | throw new HttpRequestException(HttpRequestError.Unknown, SR.net_http_client_execution_error, ex); |
| | | 385 | | } |
| | | 386 | | finally |
| | 0 | 387 | | { |
| | 0 | 388 | | if (shouldCancelBody) |
| | 0 | 389 | | { |
| | 0 | 390 | | _requestBodyCancellationSource.Cancel(); |
| | 0 | 391 | | } |
| | | 392 | | |
| | 0 | 393 | | linkedTokenRegistration.Dispose(); |
| | 0 | 394 | | if (disposeSelf) |
| | 0 | 395 | | { |
| | 0 | 396 | | await DisposeAsync().ConfigureAwait(false); |
| | 0 | 397 | | } |
| | 0 | 398 | | } |
| | 0 | 399 | | } |
| | | 400 | | |
| | | 401 | | /// <summary> |
| | | 402 | | /// Waits for the response headers to be read, and handles (Expect 100 etc.) informational statuses. |
| | | 403 | | /// </summary> |
| | | 404 | | private async Task ReadResponseAsync(CancellationToken cancellationToken) |
| | 0 | 405 | | { |
| | | 406 | | try |
| | 0 | 407 | | { |
| | 0 | 408 | | if (HttpTelemetry.Log.IsEnabled()) HttpTelemetry.Log.ResponseHeadersStart(); |
| | | 409 | | |
| | 0 | 410 | | Debug.Assert(_response == null); |
| | | 411 | | do |
| | 0 | 412 | | { |
| | 0 | 413 | | _headerState = HeaderState.StatusHeader; |
| | | 414 | | |
| | 0 | 415 | | (Http3FrameType? frameType, long payloadLength) = await ReadFrameEnvelopeAsync(cancellationToken).Co |
| | | 416 | | |
| | 0 | 417 | | if (frameType != Http3FrameType.Headers) |
| | 0 | 418 | | { |
| | 0 | 419 | | if (NetEventSource.Log.IsEnabled()) |
| | 0 | 420 | | { |
| | 0 | 421 | | Trace($"Expected HEADERS as first response frame; received {frameType}."); |
| | 0 | 422 | | } |
| | 0 | 423 | | throw new HttpIOException(HttpRequestError.InvalidResponse, SR.net_http_invalid_response); |
| | | 424 | | } |
| | | 425 | | |
| | 0 | 426 | | await ReadHeadersAsync(payloadLength, cancellationToken).ConfigureAwait(false); |
| | 0 | 427 | | Debug.Assert(_response != null); |
| | 0 | 428 | | } |
| | 0 | 429 | | while ((int)_response.StatusCode < 200); |
| | | 430 | | |
| | 0 | 431 | | _headerState = HeaderState.TrailingHeaders; |
| | | 432 | | |
| | 0 | 433 | | if (HttpTelemetry.Log.IsEnabled()) HttpTelemetry.Log.ResponseHeadersStop((int)_response.StatusCode); |
| | 0 | 434 | | } |
| | | 435 | | finally |
| | 0 | 436 | | { |
| | | 437 | | // Note that we might still observe false here even if we're responsible for the _recvBuffer disposal. |
| | | 438 | | // But in that case, we just don't return the rented buffer to the pool, which is lesser evil than writi |
| | 0 | 439 | | if (_finishingBackgroundRead) |
| | 0 | 440 | | { |
| | 0 | 441 | | _recvBuffer.Dispose(); |
| | 0 | 442 | | } |
| | 0 | 443 | | } |
| | 0 | 444 | | } |
| | | 445 | | |
| | | 446 | | private async Task SendContentAsync(HttpContent content, CancellationToken cancellationToken) |
| | 0 | 447 | | { |
| | | 448 | | try |
| | 0 | 449 | | { |
| | | 450 | | // If we're using Expect 100 Continue, wait to send content |
| | | 451 | | // until we get a response back or until our timeout elapses. |
| | 0 | 452 | | if (_expect100ContinueCompletionSource != null) |
| | 0 | 453 | | { |
| | 0 | 454 | | Timer? timer = null; |
| | | 455 | | |
| | | 456 | | try |
| | 0 | 457 | | { |
| | 0 | 458 | | if (_connection.Pool.Settings._expect100ContinueTimeout != Timeout.InfiniteTimeSpan) |
| | 0 | 459 | | { |
| | 0 | 460 | | timer = new Timer(static o => ((Http3RequestStream)o!)._expect100ContinueCompletionSource!.T |
| | 0 | 461 | | this, _connection.Pool.Settings._expect100ContinueTimeout, Timeout.InfiniteTimeSpan); |
| | 0 | 462 | | } |
| | | 463 | | |
| | 0 | 464 | | if (!await _expect100ContinueCompletionSource.Task.ConfigureAwait(false)) |
| | 0 | 465 | | { |
| | | 466 | | // We received an error response code, so the body should not be sent. |
| | 0 | 467 | | return; |
| | | 468 | | } |
| | 0 | 469 | | } |
| | | 470 | | finally |
| | 0 | 471 | | { |
| | 0 | 472 | | if (timer != null) |
| | 0 | 473 | | { |
| | 0 | 474 | | await timer.DisposeAsync().ConfigureAwait(false); |
| | 0 | 475 | | } |
| | 0 | 476 | | } |
| | 0 | 477 | | } |
| | | 478 | | |
| | 0 | 479 | | if (HttpTelemetry.Log.IsEnabled()) HttpTelemetry.Log.RequestContentStart(); |
| | | 480 | | |
| | | 481 | | // If we have a Content-Length, keep track of it so we don't over-send and so we can send in a single DA |
| | 0 | 482 | | _requestContentLengthRemaining = content.Headers.ContentLength ?? -1; |
| | | 483 | | |
| | | 484 | | long bytesWritten; |
| | 0 | 485 | | using (var writeStream = new Http3WriteStream(this)) |
| | 0 | 486 | | { |
| | 0 | 487 | | await content.CopyToAsync(writeStream, null, cancellationToken).ConfigureAwait(false); |
| | 0 | 488 | | bytesWritten = writeStream.BytesWritten; |
| | 0 | 489 | | } |
| | | 490 | | |
| | 0 | 491 | | if (_requestContentLengthRemaining > 0) |
| | 0 | 492 | | { |
| | | 493 | | // The number of bytes we actually sent doesn't match the advertised Content-Length |
| | 0 | 494 | | long contentLength = content.Headers.ContentLength.GetValueOrDefault(); |
| | 0 | 495 | | long sent = contentLength - _requestContentLengthRemaining; |
| | 0 | 496 | | throw new HttpRequestException(SR.Format(SR.net_http_request_content_length_mismatch, sent, contentL |
| | | 497 | | } |
| | | 498 | | |
| | | 499 | | // Set to 0 to recognize that the whole request body has been sent and therefore there's no need to abor |
| | 0 | 500 | | _requestContentLengthRemaining = 0; |
| | | 501 | | |
| | 0 | 502 | | if (_sendBuffer.ActiveLength != 0) |
| | 0 | 503 | | { |
| | | 504 | | // Our initial send buffer, which has our headers, is normally sent out on the first write to the Ht |
| | | 505 | | // If we get here, it means the content didn't actually do any writing. Send out the headers now. |
| | | 506 | | // Also send the FIN flag, since this is the last write. No need to call Shutdown separately. |
| | 0 | 507 | | await FlushSendBufferAsync(endStream: true, cancellationToken).ConfigureAwait(false); |
| | 0 | 508 | | } |
| | | 509 | | else |
| | 0 | 510 | | { |
| | 0 | 511 | | _stream.CompleteWrites(); |
| | 0 | 512 | | } |
| | | 513 | | |
| | 0 | 514 | | if (HttpTelemetry.Log.IsEnabled()) HttpTelemetry.Log.RequestContentStop(bytesWritten); |
| | 0 | 515 | | } |
| | 0 | 516 | | catch (HttpRequestException hex) when (hex.InnerException is QuicException qex && qex.QuicError == QuicError |
| | 0 | 517 | | { |
| | | 518 | | // The server doesn't need the whole request to respond so it's aborting its reading side gracefully, se |
| | 0 | 519 | | } |
| | | 520 | | finally |
| | 0 | 521 | | { |
| | | 522 | | // Note that we might still observe false here even if we're responsible for the _sendBuffer disposal. |
| | | 523 | | // But in that case, we just don't return the rented buffer to the pool, which is lesser evil than writi |
| | 0 | 524 | | if (_finishingBackgroundWrite) |
| | 0 | 525 | | { |
| | 0 | 526 | | _sendBuffer.Dispose(); |
| | 0 | 527 | | } |
| | 0 | 528 | | _requestSendCompleted = true; |
| | 0 | 529 | | RemoveFromConnectionIfDone(); |
| | 0 | 530 | | } |
| | 0 | 531 | | } |
| | | 532 | | |
| | | 533 | | private async ValueTask WriteRequestContentAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToke |
| | 0 | 534 | | { |
| | 0 | 535 | | if (buffer.Length == 0) |
| | 0 | 536 | | { |
| | 0 | 537 | | return; |
| | | 538 | | } |
| | | 539 | | |
| | 0 | 540 | | long remaining = _requestContentLengthRemaining; |
| | 0 | 541 | | if (remaining != -1) |
| | 0 | 542 | | { |
| | | 543 | | // This HttpContent had a precomputed length, and a DATA frame was written as part of the headers. We ca |
| | | 544 | | |
| | 0 | 545 | | if (buffer.Length > _requestContentLengthRemaining) |
| | 0 | 546 | | { |
| | 0 | 547 | | throw new HttpRequestException(SR.net_http_content_write_larger_than_content_length); |
| | | 548 | | } |
| | 0 | 549 | | _requestContentLengthRemaining -= buffer.Length; |
| | | 550 | | |
| | 0 | 551 | | if (!_singleDataFrameWritten) |
| | 0 | 552 | | { |
| | | 553 | | // Note we may not have sent headers yet; if so, _sendBuffer.ActiveLength will be > 0, and we will w |
| | | 554 | | |
| | | 555 | | // Because we have a Content-Length, we can write it in a single DATA frame. |
| | 0 | 556 | | BufferFrameEnvelope(Http3FrameType.Data, remaining); |
| | | 557 | | |
| | 0 | 558 | | await _stream.WriteAsync(_sendBuffer.ActiveMemory, cancellationToken).ConfigureAwait(false); |
| | 0 | 559 | | await _stream.WriteAsync(buffer, cancellationToken).ConfigureAwait(false); |
| | | 560 | | |
| | 0 | 561 | | _sendBuffer.Discard(_sendBuffer.ActiveLength); |
| | | 562 | | |
| | 0 | 563 | | _singleDataFrameWritten = true; |
| | 0 | 564 | | } |
| | | 565 | | else |
| | 0 | 566 | | { |
| | | 567 | | // DATA frame already sent, send just the content buffer directly. |
| | 0 | 568 | | await _stream.WriteAsync(buffer, cancellationToken).ConfigureAwait(false); |
| | 0 | 569 | | } |
| | 0 | 570 | | } |
| | | 571 | | else |
| | 0 | 572 | | { |
| | | 573 | | // Variable-length content: write both a DATA frame and buffer. (and headers, which will still be in _se |
| | | 574 | | // It's up to the HttpContent to give us sufficiently large writes to avoid excessively small DATA frame |
| | 0 | 575 | | BufferFrameEnvelope(Http3FrameType.Data, buffer.Length); |
| | | 576 | | |
| | 0 | 577 | | await _stream.WriteAsync(_sendBuffer.ActiveMemory, cancellationToken).ConfigureAwait(false); |
| | 0 | 578 | | await _stream.WriteAsync(buffer, cancellationToken).ConfigureAwait(false); |
| | | 579 | | |
| | 0 | 580 | | _sendBuffer.Discard(_sendBuffer.ActiveLength); |
| | 0 | 581 | | } |
| | 0 | 582 | | } |
| | | 583 | | |
| | | 584 | | private ValueTask FlushSendBufferAsync(bool endStream, CancellationToken cancellationToken) |
| | 0 | 585 | | { |
| | 0 | 586 | | ReadOnlyMemory<byte> toSend = _sendBuffer.ActiveMemory; |
| | 0 | 587 | | _sendBuffer.Discard(toSend.Length); |
| | 0 | 588 | | return _stream.WriteAsync(toSend, endStream, cancellationToken); |
| | 0 | 589 | | } |
| | | 590 | | |
| | | 591 | | private async ValueTask DrainContentLength0Frames(CancellationToken cancellationToken) |
| | 0 | 592 | | { |
| | | 593 | | Http3FrameType? frameType; |
| | | 594 | | long payloadLength; |
| | | 595 | | |
| | 0 | 596 | | while (true) |
| | 0 | 597 | | { |
| | 0 | 598 | | (frameType, payloadLength) = await ReadFrameEnvelopeAsync(cancellationToken).ConfigureAwait(false); |
| | | 599 | | |
| | 0 | 600 | | switch (frameType) |
| | | 601 | | { |
| | | 602 | | case Http3FrameType.Headers: |
| | | 603 | | // Pick up any trailing headers and stop processing. |
| | 0 | 604 | | await ProcessTrailersAsync(payloadLength, cancellationToken).ConfigureAwait(false); |
| | | 605 | | |
| | 0 | 606 | | goto case null; |
| | | 607 | | case null: |
| | | 608 | | // Done receiving: copy over trailing headers. |
| | 0 | 609 | | CopyTrailersToResponseMessage(_response!); |
| | | 610 | | |
| | 0 | 611 | | _responseDataPayloadRemaining = -1; // Set to -1 to indicate EOS. |
| | 0 | 612 | | return; |
| | | 613 | | case Http3FrameType.Data: |
| | | 614 | | // The sum of data frames must equal content length. Because this method is only |
| | | 615 | | // called for a Content-Length of 0, anything other than 0 here would be an error. |
| | | 616 | | // Per spec, 0-length payload is allowed. |
| | 0 | 617 | | if (payloadLength != 0) |
| | 0 | 618 | | { |
| | 0 | 619 | | if (NetEventSource.Log.IsEnabled()) |
| | 0 | 620 | | { |
| | 0 | 621 | | Trace("Response content exceeded Content-Length."); |
| | 0 | 622 | | } |
| | 0 | 623 | | throw new HttpIOException(HttpRequestError.InvalidResponse, SR.net_http_invalid_response); |
| | | 624 | | } |
| | 0 | 625 | | break; |
| | | 626 | | default: |
| | 0 | 627 | | Debug.Fail($"Received unexpected frame type {frameType}."); |
| | | 628 | | return; |
| | | 629 | | } |
| | 0 | 630 | | } |
| | 0 | 631 | | } |
| | | 632 | | |
| | | 633 | | private async ValueTask ProcessTrailersAsync(long payloadLength, CancellationToken cancellationToken) |
| | 0 | 634 | | { |
| | 0 | 635 | | _trailingHeaders = new HttpResponseHeaders(containsTrailingHeaders: true); |
| | 0 | 636 | | await ReadHeadersAsync(payloadLength, cancellationToken).ConfigureAwait(false); |
| | | 637 | | |
| | | 638 | | // In typical cases, there should be no more frames. Make sure to read the EOS. |
| | 0 | 639 | | _recvBuffer.EnsureAvailableSpace(1); |
| | 0 | 640 | | int bytesRead = await _stream.ReadAsync(_recvBuffer.AvailableMemory, cancellationToken).ConfigureAwait(false |
| | 0 | 641 | | if (bytesRead > 0) |
| | 0 | 642 | | { |
| | | 643 | | // The server may send us frames of unknown types after the trailer. Ideally we should drain the respons |
| | | 644 | | // but this is a rare case so we just stop reading and let Dispose() send an ABORT_RECEIVE. |
| | | 645 | | // Note: if a server sends additional HEADERS or DATA frames at this point, it |
| | | 646 | | // would be a connection error -- not draining the stream also means we won't catch this. |
| | 0 | 647 | | _recvBuffer.Commit(bytesRead); |
| | 0 | 648 | | _recvBuffer.Discard(bytesRead); |
| | 0 | 649 | | } |
| | 0 | 650 | | } |
| | | 651 | | |
| | | 652 | | private void CopyTrailersToResponseMessage(HttpResponseMessage responseMessage) |
| | 0 | 653 | | { |
| | 0 | 654 | | if (_trailingHeaders is not null) |
| | 0 | 655 | | { |
| | 0 | 656 | | responseMessage.StoreReceivedTrailingHeaders(_trailingHeaders); |
| | 0 | 657 | | } |
| | 0 | 658 | | } |
| | | 659 | | |
| | | 660 | | private void BufferHeaders(HttpRequestMessage request) |
| | 0 | 661 | | { |
| | 0 | 662 | | if (HttpTelemetry.Log.IsEnabled()) HttpTelemetry.Log.RequestHeadersStart(_connection.Id); |
| | | 663 | | |
| | | 664 | | // Reserve space for the header frame envelope. |
| | | 665 | | // The envelope needs to be written after headers are serialized, as we need to know the payload length firs |
| | | 666 | | const int PreHeadersReserveSpace = Http3Frame.MaximumEncodedFrameEnvelopeLength; |
| | | 667 | | |
| | | 668 | | // This should be the first write to our buffer. The trick of reserving space won't otherwise work. |
| | 0 | 669 | | Debug.Assert(_sendBuffer.ActiveLength == 0); |
| | | 670 | | |
| | | 671 | | // Reserve space for header frame envelope. |
| | 0 | 672 | | _sendBuffer.Commit(PreHeadersReserveSpace); |
| | | 673 | | |
| | | 674 | | // Add header block prefix. We aren't using dynamic table, so these are simple zeroes. |
| | | 675 | | // https://tools.ietf.org/html/draft-ietf-quic-qpack-11#section-4.5.1 |
| | 0 | 676 | | _sendBuffer.EnsureAvailableSpace(2); |
| | 0 | 677 | | _sendBuffer.AvailableSpan[0] = 0x00; // required insert count. |
| | 0 | 678 | | _sendBuffer.AvailableSpan[1] = 0x00; // s + delta base. |
| | 0 | 679 | | _sendBuffer.Commit(2); |
| | | 680 | | |
| | 0 | 681 | | BufferBytes(request.Method.Http3EncodedBytes); |
| | 0 | 682 | | BufferIndexedHeader(H3StaticTable.SchemeHttps); |
| | | 683 | | |
| | 0 | 684 | | if (request.HasHeaders && request.Headers.Host is string host) |
| | 0 | 685 | | { |
| | 0 | 686 | | BufferLiteralHeaderWithStaticNameReference(H3StaticTable.Authority, host); |
| | 0 | 687 | | } |
| | | 688 | | else |
| | 0 | 689 | | { |
| | 0 | 690 | | BufferBytes(_connection.Pool._http3EncodedAuthorityHostHeader); |
| | 0 | 691 | | } |
| | | 692 | | |
| | 0 | 693 | | Debug.Assert(request.RequestUri != null); |
| | 0 | 694 | | string pathAndQuery = request.RequestUri.PathAndQuery; |
| | 0 | 695 | | if (pathAndQuery == "/") |
| | 0 | 696 | | { |
| | 0 | 697 | | BufferIndexedHeader(H3StaticTable.PathSlash); |
| | 0 | 698 | | } |
| | | 699 | | else |
| | 0 | 700 | | { |
| | 0 | 701 | | BufferLiteralHeaderWithStaticNameReference(H3StaticTable.PathSlash, pathAndQuery); |
| | 0 | 702 | | } |
| | | 703 | | |
| | | 704 | | // The only way to reach H3 is to upgrade via an Alt-Svc header, so we can encode Alt-Used for every connect |
| | 0 | 705 | | BufferBytes(_connection.AltUsedEncodedHeaderBytes); |
| | | 706 | | |
| | 0 | 707 | | int headerListSize = 4 * HeaderField.RfcOverhead; // Scheme, Method, Authority, Path |
| | | 708 | | |
| | 0 | 709 | | if (request.HasHeaders) |
| | 0 | 710 | | { |
| | | 711 | | // H3 does not support Transfer-Encoding: chunked. |
| | 0 | 712 | | if (request.HasHeaders && request.Headers.TransferEncodingChunked == true) |
| | 0 | 713 | | { |
| | 0 | 714 | | request.Headers.TransferEncodingChunked = false; |
| | 0 | 715 | | } |
| | | 716 | | |
| | 0 | 717 | | headerListSize += BufferHeaderCollection(request.Headers); |
| | 0 | 718 | | } |
| | | 719 | | |
| | 0 | 720 | | if (_connection.Pool.Settings._useCookies) |
| | 0 | 721 | | { |
| | 0 | 722 | | string cookiesFromContainer = _connection.Pool.Settings._cookieContainer!.GetCookieHeader(request.Reques |
| | 0 | 723 | | if (cookiesFromContainer != string.Empty) |
| | 0 | 724 | | { |
| | 0 | 725 | | Encoding? valueEncoding = _connection.Pool.Settings._requestHeaderEncodingSelector?.Invoke(HttpKnown |
| | 0 | 726 | | BufferLiteralHeaderWithStaticNameReference(H3StaticTable.Cookie, cookiesFromContainer, valueEncoding |
| | 0 | 727 | | headerListSize += HttpKnownHeaderNames.Cookie.Length + HeaderField.RfcOverhead; |
| | 0 | 728 | | } |
| | 0 | 729 | | } |
| | | 730 | | |
| | 0 | 731 | | if (request.Content == null) |
| | 0 | 732 | | { |
| | 0 | 733 | | if (request.Method.MustHaveRequestBody) |
| | 0 | 734 | | { |
| | 0 | 735 | | BufferIndexedHeader(H3StaticTable.ContentLength0); |
| | 0 | 736 | | headerListSize += HttpKnownHeaderNames.ContentLength.Length + HeaderField.RfcOverhead; |
| | 0 | 737 | | } |
| | 0 | 738 | | } |
| | | 739 | | else |
| | 0 | 740 | | { |
| | 0 | 741 | | headerListSize += BufferHeaderCollection(request.Content.Headers); |
| | 0 | 742 | | } |
| | | 743 | | |
| | | 744 | | // Determine our header envelope size. |
| | | 745 | | // The reserved space was the maximum required; discard what wasn't used. |
| | 0 | 746 | | int headersLength = _sendBuffer.ActiveLength - PreHeadersReserveSpace; |
| | 0 | 747 | | int headersLengthEncodedSize = VariableLengthIntegerHelper.GetByteCount(headersLength); |
| | 0 | 748 | | _sendBuffer.Discard(PreHeadersReserveSpace - headersLengthEncodedSize - 1); |
| | | 749 | | |
| | | 750 | | // Encode header type in first byte, and payload length in subsequent bytes. |
| | 0 | 751 | | _sendBuffer.ActiveSpan[0] = (byte)Http3FrameType.Headers; |
| | 0 | 752 | | int actualHeadersLengthEncodedSize = VariableLengthIntegerHelper.WriteInteger(_sendBuffer.ActiveSpan.Slice(1 |
| | 0 | 753 | | Debug.Assert(actualHeadersLengthEncodedSize == headersLengthEncodedSize); |
| | | 754 | | |
| | | 755 | | // The headerListSize is an approximation of the total header length. |
| | | 756 | | // This is acceptable as long as the value is always >= the actual length. |
| | | 757 | | // We must avoid ever sending more than the server allowed. |
| | | 758 | | // This approach must be revisted if we ever support the dynamic table or compression when sending requests. |
| | 0 | 759 | | headerListSize += headersLength; |
| | | 760 | | |
| | 0 | 761 | | uint maxHeaderListSize = _connection.MaxHeaderListSize; |
| | 0 | 762 | | if ((uint)headerListSize > maxHeaderListSize) |
| | 0 | 763 | | { |
| | 0 | 764 | | throw new HttpRequestException(SR.Format(SR.net_http_request_headers_exceeded_length, maxHeaderListSize) |
| | | 765 | | } |
| | | 766 | | |
| | 0 | 767 | | if (HttpTelemetry.Log.IsEnabled()) HttpTelemetry.Log.RequestHeadersStop(); |
| | 0 | 768 | | } |
| | | 769 | | |
| | | 770 | | // TODO: special-case Content-Type for static table values values? |
| | | 771 | | private int BufferHeaderCollection(HttpHeaders headers) |
| | 0 | 772 | | { |
| | 0 | 773 | | HeaderEncodingSelector<HttpRequestMessage>? encodingSelector = _connection.Pool.Settings._requestHeaderEncod |
| | | 774 | | |
| | 0 | 775 | | ReadOnlySpan<HeaderEntry> entries = headers.GetEntries(); |
| | 0 | 776 | | int headerListSize = entries.Length * HeaderField.RfcOverhead; |
| | | 777 | | |
| | 0 | 778 | | foreach (HeaderEntry header in entries) |
| | 0 | 779 | | { |
| | 0 | 780 | | int headerValuesCount = HttpHeaders.GetStoreValuesIntoStringArray(header.Key, header.Value, ref _headerV |
| | 0 | 781 | | Debug.Assert(headerValuesCount > 0, "No values for header??"); |
| | 0 | 782 | | ReadOnlySpan<string> headerValues = _headerValues.AsSpan(0, headerValuesCount); |
| | | 783 | | |
| | 0 | 784 | | Encoding? valueEncoding = encodingSelector?.Invoke(header.Key.Name, _request); |
| | | 785 | | |
| | 0 | 786 | | KnownHeader? knownHeader = header.Key.KnownHeader; |
| | 0 | 787 | | if (knownHeader != null) |
| | 0 | 788 | | { |
| | | 789 | | // The Host header is not sent for HTTP/3 because we send the ":authority" pseudo-header instead |
| | | 790 | | // (see pseudo-header handling below in WriteHeaders). |
| | | 791 | | // The Connection, Upgrade and ProxyConnection headers are also not supported in HTTP/3. |
| | 0 | 792 | | if (knownHeader != KnownHeaders.Host && knownHeader != KnownHeaders.Connection && knownHeader != Kno |
| | 0 | 793 | | { |
| | | 794 | | // The length of the encoded name may be shorter than the actual name. |
| | | 795 | | // Ensure that headerListSize is always >= of the actual size. |
| | 0 | 796 | | headerListSize += knownHeader.Name.Length; |
| | | 797 | | |
| | 0 | 798 | | if (knownHeader == KnownHeaders.TE) |
| | 0 | 799 | | { |
| | | 800 | | // HTTP/2 allows only 'trailers' TE header. rfc7540 8.1.2.2 |
| | | 801 | | // HTTP/3 does not mention this one way or another; assume it has the same rule. |
| | 0 | 802 | | foreach (string value in headerValues) |
| | 0 | 803 | | { |
| | 0 | 804 | | if (string.Equals(value, "trailers", StringComparison.OrdinalIgnoreCase)) |
| | 0 | 805 | | { |
| | 0 | 806 | | BufferLiteralHeaderWithoutNameReference("TE", value, valueEncoding); |
| | 0 | 807 | | break; |
| | | 808 | | } |
| | 0 | 809 | | } |
| | 0 | 810 | | continue; |
| | | 811 | | } |
| | | 812 | | |
| | | 813 | | // For all other known headers, send them via their pre-encoded name and the associated value. |
| | 0 | 814 | | BufferBytes(knownHeader.Http3EncodedName); |
| | | 815 | | |
| | 0 | 816 | | byte[]? separator = headerValues.Length > 1 ? header.Key.SeparatorBytes : null; |
| | | 817 | | |
| | 0 | 818 | | BufferLiteralHeaderValues(headerValues, separator, valueEncoding); |
| | 0 | 819 | | } |
| | 0 | 820 | | } |
| | | 821 | | else |
| | 0 | 822 | | { |
| | | 823 | | // The header is not known: fall back to just encoding the header name and value(s). |
| | 0 | 824 | | BufferLiteralHeaderWithoutNameReference(header.Key.Name, headerValues, HttpHeaderParser.DefaultSepar |
| | 0 | 825 | | } |
| | 0 | 826 | | } |
| | | 827 | | |
| | 0 | 828 | | return headerListSize; |
| | 0 | 829 | | } |
| | | 830 | | |
| | | 831 | | private void BufferIndexedHeader(int index) |
| | 0 | 832 | | { |
| | | 833 | | int bytesWritten; |
| | 0 | 834 | | while (!QPackEncoder.EncodeStaticIndexedHeaderField(index, _sendBuffer.AvailableSpan, out bytesWritten)) |
| | 0 | 835 | | { |
| | 0 | 836 | | _sendBuffer.Grow(); |
| | 0 | 837 | | } |
| | 0 | 838 | | _sendBuffer.Commit(bytesWritten); |
| | 0 | 839 | | } |
| | | 840 | | |
| | | 841 | | private void BufferLiteralHeaderWithStaticNameReference(int nameIndex, string value, Encoding? valueEncoding = n |
| | 0 | 842 | | { |
| | | 843 | | int bytesWritten; |
| | 0 | 844 | | while (!QPackEncoder.EncodeLiteralHeaderFieldWithStaticNameReference(nameIndex, value, valueEncoding, _sendB |
| | 0 | 845 | | { |
| | 0 | 846 | | _sendBuffer.Grow(); |
| | 0 | 847 | | } |
| | 0 | 848 | | _sendBuffer.Commit(bytesWritten); |
| | 0 | 849 | | } |
| | | 850 | | |
| | | 851 | | private void BufferLiteralHeaderWithoutNameReference(string name, ReadOnlySpan<string> values, byte[] separator, |
| | 0 | 852 | | { |
| | | 853 | | int bytesWritten; |
| | 0 | 854 | | while (!QPackEncoder.EncodeLiteralHeaderFieldWithoutNameReference(name, values, separator, valueEncoding, _s |
| | 0 | 855 | | { |
| | 0 | 856 | | _sendBuffer.Grow(); |
| | 0 | 857 | | } |
| | 0 | 858 | | _sendBuffer.Commit(bytesWritten); |
| | 0 | 859 | | } |
| | | 860 | | |
| | | 861 | | private void BufferLiteralHeaderWithoutNameReference(string name, string value, Encoding? valueEncoding) |
| | 0 | 862 | | { |
| | | 863 | | int bytesWritten; |
| | 0 | 864 | | while (!QPackEncoder.EncodeLiteralHeaderFieldWithoutNameReference(name, value, valueEncoding, _sendBuffer.Av |
| | 0 | 865 | | { |
| | 0 | 866 | | _sendBuffer.Grow(); |
| | 0 | 867 | | } |
| | 0 | 868 | | _sendBuffer.Commit(bytesWritten); |
| | 0 | 869 | | } |
| | | 870 | | |
| | | 871 | | private void BufferLiteralHeaderValues(ReadOnlySpan<string> values, byte[]? separator, Encoding? valueEncoding) |
| | 0 | 872 | | { |
| | | 873 | | int bytesWritten; |
| | 0 | 874 | | while (!QPackEncoder.EncodeValueString(values, separator, valueEncoding, _sendBuffer.AvailableSpan, out byte |
| | 0 | 875 | | { |
| | 0 | 876 | | _sendBuffer.Grow(); |
| | 0 | 877 | | } |
| | 0 | 878 | | _sendBuffer.Commit(bytesWritten); |
| | 0 | 879 | | } |
| | | 880 | | |
| | | 881 | | private void BufferFrameEnvelope(Http3FrameType frameType, long payloadLength) |
| | 0 | 882 | | { |
| | | 883 | | int bytesWritten; |
| | 0 | 884 | | while (!Http3Frame.TryWriteFrameEnvelope(frameType, payloadLength, _sendBuffer.AvailableSpan, out bytesWritt |
| | 0 | 885 | | { |
| | 0 | 886 | | _sendBuffer.Grow(); |
| | 0 | 887 | | } |
| | 0 | 888 | | _sendBuffer.Commit(bytesWritten); |
| | 0 | 889 | | } |
| | | 890 | | |
| | | 891 | | private void BufferBytes(ReadOnlySpan<byte> span) |
| | 0 | 892 | | { |
| | 0 | 893 | | _sendBuffer.EnsureAvailableSpace(span.Length); |
| | 0 | 894 | | span.CopyTo(_sendBuffer.AvailableSpan); |
| | 0 | 895 | | _sendBuffer.Commit(span.Length); |
| | 0 | 896 | | } |
| | | 897 | | |
| | | 898 | | private async ValueTask<(Http3FrameType? frameType, long payloadLength)> ReadFrameEnvelopeAsync(CancellationToke |
| | 0 | 899 | | { |
| | | 900 | | long frameType, payloadLength; |
| | | 901 | | int bytesRead; |
| | | 902 | | |
| | 0 | 903 | | while (true) |
| | 0 | 904 | | { |
| | 0 | 905 | | while (!Http3Frame.TryReadIntegerPair(_recvBuffer.ActiveSpan, out frameType, out payloadLength, out byte |
| | 0 | 906 | | { |
| | 0 | 907 | | _recvBuffer.EnsureAvailableSpace(VariableLengthIntegerHelper.MaximumEncodedLength * 2); |
| | 0 | 908 | | bytesRead = await _stream.ReadAsync(_recvBuffer.AvailableMemory, cancellationToken).ConfigureAwait(f |
| | | 909 | | |
| | 0 | 910 | | if (bytesRead != 0) |
| | 0 | 911 | | { |
| | 0 | 912 | | _recvBuffer.Commit(bytesRead); |
| | 0 | 913 | | } |
| | 0 | 914 | | else if (_recvBuffer.ActiveLength == 0) |
| | 0 | 915 | | { |
| | | 916 | | // End of stream. |
| | 0 | 917 | | return (null, 0); |
| | | 918 | | } |
| | | 919 | | else |
| | 0 | 920 | | { |
| | | 921 | | // Our buffer has partial frame data in it but not enough to complete the read: bail out. |
| | 0 | 922 | | throw new HttpIOException(HttpRequestError.ResponseEnded, SR.net_http_invalid_response_premature |
| | | 923 | | } |
| | 0 | 924 | | } |
| | | 925 | | |
| | 0 | 926 | | _recvBuffer.Discard(bytesRead); |
| | | 927 | | |
| | 0 | 928 | | if (NetEventSource.Log.IsEnabled()) |
| | 0 | 929 | | { |
| | 0 | 930 | | Trace($"Received frame {frameType} of length {payloadLength}."); |
| | 0 | 931 | | } |
| | | 932 | | |
| | 0 | 933 | | switch ((Http3FrameType)frameType) |
| | | 934 | | { |
| | | 935 | | case Http3FrameType.Headers: |
| | | 936 | | case Http3FrameType.Data: |
| | 0 | 937 | | return ((Http3FrameType)frameType, payloadLength); |
| | | 938 | | case Http3FrameType.Settings: // These frames should only be received on a control stream, not a res |
| | | 939 | | case Http3FrameType.GoAway: |
| | | 940 | | case Http3FrameType.MaxPushId: |
| | | 941 | | case Http3FrameType.ReservedHttp2Priority: // These frames are explicitly reserved and must never be |
| | | 942 | | case Http3FrameType.ReservedHttp2Ping: |
| | | 943 | | case Http3FrameType.ReservedHttp2WindowUpdate: |
| | | 944 | | case Http3FrameType.ReservedHttp2Continuation: |
| | 0 | 945 | | throw HttpProtocolException.CreateHttp3ConnectionException(Http3ErrorCode.UnexpectedFrame); |
| | | 946 | | case Http3FrameType.PushPromise: |
| | | 947 | | case Http3FrameType.CancelPush: |
| | | 948 | | // Because we haven't sent any MAX_PUSH_ID frames, any of these push-related |
| | | 949 | | // frames that the server sends will have an out-of-range push ID. |
| | 0 | 950 | | throw HttpProtocolException.CreateHttp3ConnectionException(Http3ErrorCode.IdError); |
| | | 951 | | default: |
| | | 952 | | // Unknown frame types should be skipped. |
| | 0 | 953 | | await SkipUnknownPayloadAsync(payloadLength, cancellationToken).ConfigureAwait(false); |
| | 0 | 954 | | break; |
| | | 955 | | } |
| | 0 | 956 | | } |
| | 0 | 957 | | } |
| | | 958 | | |
| | | 959 | | private async ValueTask ReadHeadersAsync(long headersLength, CancellationToken cancellationToken) |
| | 0 | 960 | | { |
| | | 961 | | // TODO: this header budget is sent as SETTINGS_MAX_HEADER_LIST_SIZE, so it should not use frame payload but |
| | | 962 | | // https://tools.ietf.org/html/draft-ietf-quic-http-24#section-4.1.1 |
| | 0 | 963 | | if (headersLength > _headerBudgetRemaining) |
| | 0 | 964 | | { |
| | 0 | 965 | | _stream.Abort(QuicAbortDirection.Read, (long)Http3ErrorCode.ExcessiveLoad); |
| | 0 | 966 | | throw new HttpRequestException(HttpRequestError.ConfigurationLimitExceeded, SR.Format(SR.net_http_respon |
| | | 967 | | } |
| | | 968 | | |
| | 0 | 969 | | _headerBudgetRemaining -= (int)headersLength; |
| | | 970 | | |
| | 0 | 971 | | while (headersLength != 0) |
| | 0 | 972 | | { |
| | 0 | 973 | | if (_recvBuffer.ActiveLength == 0) |
| | 0 | 974 | | { |
| | 0 | 975 | | _recvBuffer.EnsureAvailableSpace(1); |
| | | 976 | | |
| | 0 | 977 | | int bytesRead = await _stream.ReadAsync(_recvBuffer.AvailableMemory, cancellationToken).ConfigureAwa |
| | 0 | 978 | | if (bytesRead != 0) |
| | 0 | 979 | | { |
| | 0 | 980 | | _recvBuffer.Commit(bytesRead); |
| | 0 | 981 | | } |
| | | 982 | | else |
| | 0 | 983 | | { |
| | 0 | 984 | | if (NetEventSource.Log.IsEnabled()) Trace($"Server closed response stream before entire header p |
| | 0 | 985 | | throw new HttpIOException(HttpRequestError.ResponseEnded, SR.net_http_invalid_response_premature |
| | | 986 | | } |
| | 0 | 987 | | } |
| | | 988 | | |
| | 0 | 989 | | int processLength = (int)Math.Min(headersLength, _recvBuffer.ActiveLength); |
| | 0 | 990 | | bool endHeaders = headersLength == processLength; |
| | | 991 | | |
| | 0 | 992 | | _headerDecoder.Decode(_recvBuffer.ActiveSpan.Slice(0, processLength), endHeaders, this); |
| | 0 | 993 | | _recvBuffer.Discard(processLength); |
| | 0 | 994 | | headersLength -= processLength; |
| | 0 | 995 | | } |
| | | 996 | | |
| | | 997 | | // Reset decoder state. Require because one decoder instance is reused to decode headers and trailers. |
| | 0 | 998 | | _headerDecoder.Reset(); |
| | 0 | 999 | | } |
| | | 1000 | | |
| | | 1001 | | void IHttpStreamHeadersHandler.OnHeader(ReadOnlySpan<byte> name, ReadOnlySpan<byte> value) |
| | 0 | 1002 | | { |
| | 0 | 1003 | | Debug.Assert(name.Length > 0); |
| | 0 | 1004 | | if (!HeaderDescriptor.TryGet(name, out HeaderDescriptor descriptor)) |
| | 0 | 1005 | | { |
| | | 1006 | | // Invalid header name |
| | 0 | 1007 | | throw new HttpRequestException(HttpRequestError.InvalidResponse, SR.Format(SR.net_http_invalid_response_ |
| | | 1008 | | } |
| | 0 | 1009 | | OnHeader(staticIndex: null, descriptor, staticValue: default, literalValue: value); |
| | 0 | 1010 | | } |
| | | 1011 | | |
| | | 1012 | | void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index) |
| | 0 | 1013 | | { |
| | 0 | 1014 | | GetStaticQPackHeader(index, out HeaderDescriptor descriptor, out string? knownValue); |
| | 0 | 1015 | | OnHeader(index, descriptor, knownValue, literalValue: default); |
| | 0 | 1016 | | } |
| | | 1017 | | |
| | | 1018 | | void IHttpStreamHeadersHandler.OnStaticIndexedHeader(int index, ReadOnlySpan<byte> value) |
| | 0 | 1019 | | { |
| | 0 | 1020 | | GetStaticQPackHeader(index, out HeaderDescriptor descriptor, knownValue: out _); |
| | 0 | 1021 | | OnHeader(index, descriptor, staticValue: null, literalValue: value); |
| | 0 | 1022 | | } |
| | | 1023 | | |
| | | 1024 | | void IHttpStreamHeadersHandler.OnDynamicIndexedHeader(int? index, ReadOnlySpan<byte> name, ReadOnlySpan<byte> va |
| | 0 | 1025 | | { |
| | 0 | 1026 | | ((IHttpStreamHeadersHandler)this).OnHeader(name, value); |
| | 0 | 1027 | | } |
| | | 1028 | | |
| | | 1029 | | private void GetStaticQPackHeader(int index, out HeaderDescriptor descriptor, out string? knownValue) |
| | 0 | 1030 | | { |
| | 0 | 1031 | | if (!HeaderDescriptor.TryGetStaticQPackHeader(index, out descriptor, out knownValue)) |
| | 0 | 1032 | | { |
| | 0 | 1033 | | if (NetEventSource.Log.IsEnabled()) Trace($"Response contains invalid static header index '{index}'."); |
| | 0 | 1034 | | throw HttpProtocolException.CreateHttp3ConnectionException(Http3ErrorCode.ProtocolError); |
| | | 1035 | | } |
| | 0 | 1036 | | } |
| | | 1037 | | |
| | | 1038 | | /// <param name="staticIndex">The static index of the header, if any.</param> |
| | | 1039 | | /// <param name="descriptor">A descriptor for either a known header or unknown header.</param> |
| | | 1040 | | /// <param name="staticValue">The static indexed value, if any.</param> |
| | | 1041 | | /// <param name="literalValue">The literal ASCII value, if any.</param> |
| | | 1042 | | /// <remarks>One of <paramref name="staticValue"/> or <paramref name="literalValue"/> will be set.</remarks> |
| | | 1043 | | private void OnHeader(int? staticIndex, HeaderDescriptor descriptor, string? staticValue, ReadOnlySpan<byte> lit |
| | 0 | 1044 | | { |
| | 0 | 1045 | | if (descriptor.Name[0] == ':') |
| | 0 | 1046 | | { |
| | 0 | 1047 | | if (!descriptor.Equals(KnownHeaders.PseudoStatus)) |
| | 0 | 1048 | | { |
| | 0 | 1049 | | if (NetEventSource.Log.IsEnabled()) Trace($"Received unknown pseudo-header '{descriptor.Name}'."); |
| | 0 | 1050 | | throw HttpProtocolException.CreateHttp3ConnectionException(Http3ErrorCode.ProtocolError); |
| | | 1051 | | } |
| | | 1052 | | |
| | 0 | 1053 | | if (_headerState != HeaderState.StatusHeader) |
| | 0 | 1054 | | { |
| | 0 | 1055 | | if (NetEventSource.Log.IsEnabled()) Trace("Received extra status header."); |
| | 0 | 1056 | | throw HttpProtocolException.CreateHttp3ConnectionException(Http3ErrorCode.ProtocolError); |
| | | 1057 | | } |
| | | 1058 | | |
| | | 1059 | | int statusCode; |
| | 0 | 1060 | | if (staticValue != null) // Indexed Header Field -- both name and value are taken from the table |
| | 0 | 1061 | | { |
| | 0 | 1062 | | statusCode = staticIndex switch |
| | 0 | 1063 | | { |
| | 0 | 1064 | | H3StaticTable.Status103 => 103, |
| | 0 | 1065 | | H3StaticTable.Status200 => 200, |
| | 0 | 1066 | | H3StaticTable.Status304 => 304, |
| | 0 | 1067 | | H3StaticTable.Status404 => 404, |
| | 0 | 1068 | | H3StaticTable.Status503 => 503, |
| | 0 | 1069 | | H3StaticTable.Status100 => 100, |
| | 0 | 1070 | | H3StaticTable.Status204 => 204, |
| | 0 | 1071 | | H3StaticTable.Status206 => 206, |
| | 0 | 1072 | | H3StaticTable.Status302 => 302, |
| | 0 | 1073 | | H3StaticTable.Status400 => 400, |
| | 0 | 1074 | | H3StaticTable.Status403 => 403, |
| | 0 | 1075 | | H3StaticTable.Status421 => 421, |
| | 0 | 1076 | | H3StaticTable.Status425 => 425, |
| | 0 | 1077 | | H3StaticTable.Status500 => 500, |
| | 0 | 1078 | | // We should never get here, at least while we only use static table. But we can still parse sta |
| | 0 | 1079 | | _ => ParseStatusCode(staticIndex, staticValue) |
| | 0 | 1080 | | }; |
| | | 1081 | | |
| | | 1082 | | int ParseStatusCode(int? index, string value) |
| | 0 | 1083 | | { |
| | 0 | 1084 | | string message = $"Unexpected QPACK table reference for Status code: index={index} value=\'{valu |
| | 0 | 1085 | | Debug.Fail(message); |
| | | 1086 | | if (NetEventSource.Log.IsEnabled()) Trace(message); |
| | | 1087 | | |
| | | 1088 | | // TODO: The parsing is not optimal, but I don't expect this line to be executed at all for now. |
| | | 1089 | | return HttpConnectionBase.ParseStatusCode(Encoding.ASCII.GetBytes(value)); |
| | | 1090 | | } |
| | 0 | 1091 | | } |
| | | 1092 | | else // Literal Header Field With Name Reference -- only name is taken from the table |
| | 0 | 1093 | | { |
| | 0 | 1094 | | statusCode = HttpConnectionBase.ParseStatusCode(literalValue); |
| | 0 | 1095 | | } |
| | | 1096 | | |
| | 0 | 1097 | | _response = new HttpResponseMessage() |
| | 0 | 1098 | | { |
| | 0 | 1099 | | Version = HttpVersion.Version30, |
| | 0 | 1100 | | RequestMessage = _request, |
| | 0 | 1101 | | Content = new HttpConnectionResponseContent(), |
| | 0 | 1102 | | StatusCode = (HttpStatusCode)statusCode |
| | 0 | 1103 | | }; |
| | | 1104 | | |
| | 0 | 1105 | | if (statusCode < 200) |
| | 0 | 1106 | | { |
| | | 1107 | | // Informational responses should not contain headers -- skip them. |
| | 0 | 1108 | | _headerState = HeaderState.SkipExpect100Headers; |
| | | 1109 | | |
| | 0 | 1110 | | if (_response.StatusCode == HttpStatusCode.Continue && _expect100ContinueCompletionSource != null) |
| | 0 | 1111 | | { |
| | 0 | 1112 | | _expect100ContinueCompletionSource.TrySetResult(true); |
| | 0 | 1113 | | } |
| | 0 | 1114 | | } |
| | | 1115 | | else |
| | 0 | 1116 | | { |
| | 0 | 1117 | | _headerState = HeaderState.ResponseHeaders; |
| | 0 | 1118 | | if (_expect100ContinueCompletionSource != null) |
| | 0 | 1119 | | { |
| | | 1120 | | // If the final status code is >= 300, skip sending the body. |
| | 0 | 1121 | | bool shouldSendBody = (statusCode < 300); |
| | | 1122 | | |
| | 0 | 1123 | | if (NetEventSource.Log.IsEnabled()) Trace($"Expecting 100 Continue but received final status {st |
| | 0 | 1124 | | _expect100ContinueCompletionSource.TrySetResult(shouldSendBody); |
| | 0 | 1125 | | } |
| | 0 | 1126 | | } |
| | 0 | 1127 | | } |
| | 0 | 1128 | | else if (_headerState == HeaderState.SkipExpect100Headers) |
| | 0 | 1129 | | { |
| | | 1130 | | // Ignore any headers that came as part of an informational (i.e. 100 Continue) response. |
| | 0 | 1131 | | return; |
| | | 1132 | | } |
| | | 1133 | | else |
| | 0 | 1134 | | { |
| | 0 | 1135 | | string? headerValue = staticValue; |
| | | 1136 | | |
| | 0 | 1137 | | if (headerValue is null) |
| | 0 | 1138 | | { |
| | 0 | 1139 | | Encoding? encoding = _connection.Pool.Settings._responseHeaderEncodingSelector?.Invoke(descriptor.Na |
| | 0 | 1140 | | headerValue = _connection.GetResponseHeaderValueWithCaching(descriptor, literalValue, encoding); |
| | 0 | 1141 | | } |
| | | 1142 | | |
| | 0 | 1143 | | switch (_headerState) |
| | | 1144 | | { |
| | | 1145 | | case HeaderState.StatusHeader: |
| | 0 | 1146 | | if (NetEventSource.Log.IsEnabled()) Trace($"Received headers without :status."); |
| | 0 | 1147 | | throw HttpProtocolException.CreateHttp3ConnectionException(Http3ErrorCode.ProtocolError); |
| | 0 | 1148 | | case HeaderState.ResponseHeaders when descriptor.HeaderType.HasFlag(HttpHeaderType.Content): |
| | 0 | 1149 | | _response!.Content!.Headers.TryAddWithoutValidation(descriptor, headerValue); |
| | 0 | 1150 | | break; |
| | | 1151 | | case HeaderState.ResponseHeaders: |
| | 0 | 1152 | | _response!.Headers.TryAddWithoutValidation(descriptor.HeaderType.HasFlag(HttpHeaderType.Request) |
| | 0 | 1153 | | break; |
| | | 1154 | | case HeaderState.TrailingHeaders: |
| | 0 | 1155 | | _trailingHeaders!.TryAddWithoutValidation(descriptor.HeaderType.HasFlag(HttpHeaderType.Request) |
| | 0 | 1156 | | break; |
| | | 1157 | | default: |
| | 0 | 1158 | | Debug.Fail($"Unexpected {nameof(Http3RequestStream)}.{nameof(_headerState)} '{_headerState}'."); |
| | | 1159 | | break; |
| | | 1160 | | } |
| | 0 | 1161 | | } |
| | 0 | 1162 | | } |
| | | 1163 | | |
| | | 1164 | | void IHttpStreamHeadersHandler.OnHeadersComplete(bool endStream) |
| | 0 | 1165 | | { |
| | 0 | 1166 | | Debug.Fail($"This has no use in HTTP/3 and should never be called by {nameof(QPackDecoder)}."); |
| | | 1167 | | } |
| | | 1168 | | |
| | | 1169 | | private async ValueTask SkipUnknownPayloadAsync(long payloadLength, CancellationToken cancellationToken) |
| | 0 | 1170 | | { |
| | 0 | 1171 | | while (payloadLength != 0) |
| | 0 | 1172 | | { |
| | 0 | 1173 | | if (_recvBuffer.ActiveLength == 0) |
| | 0 | 1174 | | { |
| | 0 | 1175 | | _recvBuffer.EnsureAvailableSpace(1); |
| | 0 | 1176 | | int bytesRead = await _stream.ReadAsync(_recvBuffer.AvailableMemory, cancellationToken).ConfigureAwa |
| | | 1177 | | |
| | 0 | 1178 | | if (bytesRead != 0) |
| | 0 | 1179 | | { |
| | 0 | 1180 | | _recvBuffer.Commit(bytesRead); |
| | 0 | 1181 | | } |
| | | 1182 | | else |
| | 0 | 1183 | | { |
| | | 1184 | | // Our buffer has partial frame data in it but not enough to complete the read: bail out. |
| | 0 | 1185 | | throw HttpProtocolException.CreateHttp3ConnectionException(Http3ErrorCode.FrameError); |
| | | 1186 | | } |
| | 0 | 1187 | | } |
| | | 1188 | | |
| | 0 | 1189 | | long readLength = Math.Min(payloadLength, _recvBuffer.ActiveLength); |
| | 0 | 1190 | | _recvBuffer.Discard((int)readLength); |
| | 0 | 1191 | | payloadLength -= readLength; |
| | 0 | 1192 | | } |
| | 0 | 1193 | | } |
| | | 1194 | | |
| | | 1195 | | private int ReadResponseContent(HttpResponseMessage response, Span<byte> buffer) |
| | 0 | 1196 | | { |
| | | 1197 | | // Response headers should be done reading by the time this is called. _response is nulled out as part of th |
| | | 1198 | | // Verify that this is being called in correct order. |
| | 0 | 1199 | | Debug.Assert(_response == null); |
| | | 1200 | | |
| | | 1201 | | try |
| | 0 | 1202 | | { |
| | 0 | 1203 | | int totalBytesRead = 0; |
| | | 1204 | | |
| | | 1205 | | do |
| | 0 | 1206 | | { |
| | | 1207 | | // Sync over async here -- QUIC implementation does it per-I/O already; this is at least more coarse |
| | 0 | 1208 | | if (_responseDataPayloadRemaining <= 0 && !ReadNextDataFrameAsync(response, CancellationToken.None). |
| | 0 | 1209 | | { |
| | | 1210 | | // End of stream. |
| | 0 | 1211 | | _responseRecvCompleted = true; |
| | 0 | 1212 | | RemoveFromConnectionIfDone(); |
| | 0 | 1213 | | break; |
| | | 1214 | | } |
| | | 1215 | | |
| | 0 | 1216 | | if (_recvBuffer.ActiveLength != 0) |
| | 0 | 1217 | | { |
| | | 1218 | | // Some of the payload is in our receive buffer, so copy it. |
| | | 1219 | | |
| | 0 | 1220 | | int copyLen = (int)Math.Min(buffer.Length, Math.Min(_responseDataPayloadRemaining, _recvBuffer.A |
| | 0 | 1221 | | _recvBuffer.ActiveSpan.Slice(0, copyLen).CopyTo(buffer); |
| | | 1222 | | |
| | 0 | 1223 | | totalBytesRead += copyLen; |
| | 0 | 1224 | | _responseDataPayloadRemaining -= copyLen; |
| | 0 | 1225 | | _recvBuffer.Discard(copyLen); |
| | 0 | 1226 | | buffer = buffer.Slice(copyLen); |
| | | 1227 | | |
| | | 1228 | | // Stop, if we've reached the end of a data frame and start of the next data frame is not buffer |
| | | 1229 | | // Waiting for the next data frame may cause a hang, e.g. in echo scenario |
| | | 1230 | | // TODO: this is inefficient if data is already available in transport |
| | 0 | 1231 | | if (_responseDataPayloadRemaining == 0 && _recvBuffer.ActiveLength == 0) |
| | 0 | 1232 | | { |
| | 0 | 1233 | | break; |
| | | 1234 | | } |
| | 0 | 1235 | | } |
| | | 1236 | | else |
| | 0 | 1237 | | { |
| | | 1238 | | // Receive buffer is empty -- bypass it and read directly into user's buffer. |
| | | 1239 | | |
| | 0 | 1240 | | int copyLen = (int)Math.Min(buffer.Length, _responseDataPayloadRemaining); |
| | 0 | 1241 | | int bytesRead = _stream.Read(buffer.Slice(0, copyLen)); |
| | | 1242 | | |
| | 0 | 1243 | | if (bytesRead == 0 && buffer.Length != 0) |
| | 0 | 1244 | | { |
| | 0 | 1245 | | throw new HttpIOException(HttpRequestError.ResponseEnded, SR.Format(SR.net_http_invalid_resp |
| | | 1246 | | } |
| | | 1247 | | |
| | 0 | 1248 | | totalBytesRead += bytesRead; |
| | 0 | 1249 | | _responseDataPayloadRemaining -= bytesRead; |
| | 0 | 1250 | | buffer = buffer.Slice(bytesRead); |
| | | 1251 | | |
| | | 1252 | | // Stop, even if we are in the middle of a data frame. Waiting for the next data may cause a han |
| | | 1253 | | // TODO: this is inefficient if data is already available in transport |
| | 0 | 1254 | | break; |
| | | 1255 | | } |
| | 0 | 1256 | | } |
| | 0 | 1257 | | while (buffer.Length != 0); |
| | | 1258 | | |
| | 0 | 1259 | | return totalBytesRead; |
| | | 1260 | | } |
| | 0 | 1261 | | catch (Exception ex) |
| | 0 | 1262 | | { |
| | 0 | 1263 | | HandleReadResponseContentException(ex, CancellationToken.None); |
| | | 1264 | | return 0; // never reached. |
| | | 1265 | | } |
| | 0 | 1266 | | } |
| | | 1267 | | |
| | | 1268 | | private async ValueTask<int> ReadResponseContentAsync(HttpResponseMessage response, Memory<byte> buffer, Cancell |
| | 0 | 1269 | | { |
| | | 1270 | | // Response headers should be done reading by the time this is called. _response is nulled out as part of th |
| | | 1271 | | // Verify that this is being called in correct order. |
| | 0 | 1272 | | Debug.Assert(_response == null); |
| | | 1273 | | |
| | | 1274 | | try |
| | 0 | 1275 | | { |
| | 0 | 1276 | | int totalBytesRead = 0; |
| | | 1277 | | |
| | | 1278 | | do |
| | 0 | 1279 | | { |
| | 0 | 1280 | | if (_responseDataPayloadRemaining <= 0 && !await ReadNextDataFrameAsync(response, cancellationToken) |
| | 0 | 1281 | | { |
| | | 1282 | | // End of stream. |
| | 0 | 1283 | | _responseRecvCompleted = true; |
| | 0 | 1284 | | RemoveFromConnectionIfDone(); |
| | 0 | 1285 | | break; |
| | | 1286 | | } |
| | | 1287 | | |
| | 0 | 1288 | | if (_recvBuffer.ActiveLength != 0) |
| | 0 | 1289 | | { |
| | | 1290 | | // Some of the payload is in our receive buffer, so copy it. |
| | | 1291 | | |
| | 0 | 1292 | | int copyLen = (int)Math.Min(buffer.Length, Math.Min(_responseDataPayloadRemaining, _recvBuffer.A |
| | 0 | 1293 | | _recvBuffer.ActiveSpan.Slice(0, copyLen).CopyTo(buffer.Span); |
| | | 1294 | | |
| | 0 | 1295 | | totalBytesRead += copyLen; |
| | 0 | 1296 | | _responseDataPayloadRemaining -= copyLen; |
| | 0 | 1297 | | _recvBuffer.Discard(copyLen); |
| | 0 | 1298 | | buffer = buffer.Slice(copyLen); |
| | | 1299 | | |
| | | 1300 | | // Stop, if we've reached the end of a data frame and start of the next data frame is not buffer |
| | | 1301 | | // Waiting for the next data frame may cause a hang, e.g. in echo scenario |
| | | 1302 | | // TODO: this is inefficient if data is already available in transport |
| | 0 | 1303 | | if (_responseDataPayloadRemaining == 0 && _recvBuffer.ActiveLength == 0) |
| | 0 | 1304 | | { |
| | 0 | 1305 | | break; |
| | | 1306 | | } |
| | 0 | 1307 | | } |
| | | 1308 | | else |
| | 0 | 1309 | | { |
| | | 1310 | | // Receive buffer is empty -- bypass it and read directly into user's buffer. |
| | | 1311 | | |
| | 0 | 1312 | | int copyLen = (int)Math.Min(buffer.Length, _responseDataPayloadRemaining); |
| | 0 | 1313 | | int bytesRead = await _stream.ReadAsync(buffer.Slice(0, copyLen), cancellationToken).ConfigureAw |
| | | 1314 | | |
| | 0 | 1315 | | if (bytesRead == 0 && buffer.Length != 0) |
| | 0 | 1316 | | { |
| | 0 | 1317 | | throw new HttpIOException(HttpRequestError.ResponseEnded, SR.Format(SR.net_http_invalid_resp |
| | | 1318 | | } |
| | | 1319 | | |
| | 0 | 1320 | | totalBytesRead += bytesRead; |
| | 0 | 1321 | | _responseDataPayloadRemaining -= bytesRead; |
| | 0 | 1322 | | buffer = buffer.Slice(bytesRead); |
| | | 1323 | | |
| | | 1324 | | // Stop, even if we are in the middle of a data frame. Waiting for the next data may cause a han |
| | | 1325 | | // TODO: this is inefficient if data is already available in transport |
| | 0 | 1326 | | break; |
| | | 1327 | | } |
| | 0 | 1328 | | } |
| | 0 | 1329 | | while (buffer.Length != 0); |
| | | 1330 | | |
| | 0 | 1331 | | return totalBytesRead; |
| | | 1332 | | } |
| | 0 | 1333 | | catch (Exception ex) |
| | 0 | 1334 | | { |
| | 0 | 1335 | | HandleReadResponseContentException(ex, cancellationToken); |
| | | 1336 | | return 0; // never reached. |
| | | 1337 | | } |
| | 0 | 1338 | | } |
| | | 1339 | | |
| | | 1340 | | [DoesNotReturn] |
| | | 1341 | | private void HandleReadResponseContentException(Exception ex, CancellationToken cancellationToken) |
| | 0 | 1342 | | { |
| | | 1343 | | // The stream is, or is going to be aborted |
| | 0 | 1344 | | _responseRecvCompleted = true; |
| | 0 | 1345 | | RemoveFromConnectionIfDone(); |
| | | 1346 | | |
| | 0 | 1347 | | switch (ex) |
| | | 1348 | | { |
| | 0 | 1349 | | case QuicException e when (e.QuicError == QuicError.StreamAborted): |
| | | 1350 | | // Peer aborted the stream |
| | 0 | 1351 | | Debug.Assert(e.ApplicationErrorCode.HasValue); |
| | 0 | 1352 | | throw HttpProtocolException.CreateHttp3StreamException((Http3ErrorCode)e.ApplicationErrorCode.Value, |
| | | 1353 | | |
| | 0 | 1354 | | case QuicException e when (e.QuicError == QuicError.ConnectionAborted): |
| | | 1355 | | // Our connection was reset. Start aborting the connection. |
| | 0 | 1356 | | Debug.Assert(e.ApplicationErrorCode.HasValue); |
| | 0 | 1357 | | HttpProtocolException exception = HttpProtocolException.CreateHttp3ConnectionException((Http3ErrorCo |
| | 0 | 1358 | | _connection.Abort(exception); |
| | 0 | 1359 | | throw exception; |
| | | 1360 | | |
| | 0 | 1361 | | case QuicException e when (e.QuicError == QuicError.OperationAborted && _connection.AbortException != nu |
| | | 1362 | | // we closed the connection already, propagate the AbortException |
| | 0 | 1363 | | HttpRequestError httpRequestError = _connection.AbortException is HttpProtocolException |
| | 0 | 1364 | | ? HttpRequestError.HttpProtocolError |
| | 0 | 1365 | | : HttpRequestError.Unknown; |
| | 0 | 1366 | | throw new HttpRequestException(httpRequestError, SR.net_http_client_execution_error, _connection.Abo |
| | | 1367 | | |
| | 0 | 1368 | | case QuicException e when (e.QuicError == QuicError.OperationAborted && cancellationToken.IsCancellation |
| | | 1369 | | // It is possible for QuicStream's code to throw an |
| | | 1370 | | // OperationAborted QuicException when cancellation is requested. |
| | 0 | 1371 | | throw new TaskCanceledException(e.Message, e, cancellationToken); |
| | | 1372 | | |
| | | 1373 | | case HttpIOException: |
| | 0 | 1374 | | _connection.Abort(ex); |
| | 0 | 1375 | | ExceptionDispatchInfo.Throw(ex); // Rethrow. |
| | | 1376 | | return; // Never reached. |
| | | 1377 | | |
| | 0 | 1378 | | case OperationCanceledException oce when oce.CancellationToken == cancellationToken: |
| | 0 | 1379 | | _stream.Abort(QuicAbortDirection.Read, (long)Http3ErrorCode.RequestCancelled); |
| | 0 | 1380 | | ExceptionDispatchInfo.Throw(ex); // Rethrow. |
| | | 1381 | | return; // Never reached. |
| | | 1382 | | } |
| | | 1383 | | |
| | 0 | 1384 | | _stream.Abort(QuicAbortDirection.Read, (long)Http3ErrorCode.InternalError); |
| | 0 | 1385 | | throw new HttpIOException(HttpRequestError.Unknown, SR.net_http_client_execution_error, new HttpRequestExcep |
| | 0 | 1386 | | } |
| | | 1387 | | |
| | | 1388 | | private async ValueTask<bool> ReadNextDataFrameAsync(HttpResponseMessage response, CancellationToken cancellatio |
| | 0 | 1389 | | { |
| | 0 | 1390 | | if (_responseDataPayloadRemaining == -1) |
| | 0 | 1391 | | { |
| | | 1392 | | // EOS -- this branch will only be taken if user calls Read again after EOS. |
| | 0 | 1393 | | return false; |
| | | 1394 | | } |
| | | 1395 | | |
| | | 1396 | | Http3FrameType? frameType; |
| | | 1397 | | long payloadLength; |
| | | 1398 | | |
| | 0 | 1399 | | while (true) |
| | 0 | 1400 | | { |
| | 0 | 1401 | | (frameType, payloadLength) = await ReadFrameEnvelopeAsync(cancellationToken).ConfigureAwait(false); |
| | | 1402 | | |
| | 0 | 1403 | | switch (frameType) |
| | | 1404 | | { |
| | | 1405 | | case Http3FrameType.Data: |
| | | 1406 | | // Ignore DATA frames with 0 length. |
| | 0 | 1407 | | if (payloadLength == 0) |
| | 0 | 1408 | | { |
| | 0 | 1409 | | continue; |
| | | 1410 | | } |
| | 0 | 1411 | | _responseDataPayloadRemaining = payloadLength; |
| | 0 | 1412 | | return true; |
| | | 1413 | | case Http3FrameType.Headers: |
| | | 1414 | | // Pick up any trailing headers and stop processing. |
| | 0 | 1415 | | await ProcessTrailersAsync(payloadLength, cancellationToken).ConfigureAwait(false); |
| | | 1416 | | |
| | 0 | 1417 | | goto case null; |
| | | 1418 | | case null: |
| | | 1419 | | // End of stream. |
| | 0 | 1420 | | CopyTrailersToResponseMessage(response); |
| | | 1421 | | |
| | 0 | 1422 | | _responseDataPayloadRemaining = -1; // Set to -1 to indicate EOS. |
| | 0 | 1423 | | return false; |
| | | 1424 | | } |
| | 0 | 1425 | | } |
| | 0 | 1426 | | } |
| | | 1427 | | |
| | | 1428 | | public void Trace(string message, [CallerMemberName] string? memberName = null) => |
| | 0 | 1429 | | _connection.Trace(StreamId, message, memberName); |
| | | 1430 | | |
| | | 1431 | | private void AbortStream() |
| | 0 | 1432 | | { |
| | | 1433 | | // If the request body isn't completed, cancel it now. |
| | 0 | 1434 | | if (_requestContentLengthRemaining != 0) // 0 is used for the end of content writing, -1 is used for unknown |
| | 0 | 1435 | | { |
| | 0 | 1436 | | _stream.Abort(QuicAbortDirection.Write, (long)Http3ErrorCode.RequestCancelled); |
| | 0 | 1437 | | } |
| | | 1438 | | // If the response body isn't completed, cancel it now. |
| | 0 | 1439 | | if (_responseDataPayloadRemaining != -1) // -1 is used for EOF, 0 for consumed DATA frame payload before the |
| | 0 | 1440 | | { |
| | 0 | 1441 | | _stream.Abort(QuicAbortDirection.Read, (long)Http3ErrorCode.RequestCancelled); |
| | 0 | 1442 | | } |
| | 0 | 1443 | | } |
| | | 1444 | | |
| | | 1445 | | // TODO: it may be possible for Http3RequestStream to implement Stream directly and avoid this allocation. |
| | | 1446 | | private sealed class Http3ReadStream : HttpBaseStream |
| | | 1447 | | { |
| | | 1448 | | private Http3RequestStream? _stream; |
| | | 1449 | | private HttpResponseMessage? _response; |
| | | 1450 | | |
| | 0 | 1451 | | public override bool CanRead => _stream != null; |
| | | 1452 | | |
| | 0 | 1453 | | public override bool CanWrite => false; |
| | | 1454 | | |
| | 0 | 1455 | | public Http3ReadStream(Http3RequestStream stream) |
| | 0 | 1456 | | { |
| | 0 | 1457 | | _stream = stream; |
| | 0 | 1458 | | _response = stream._response; |
| | 0 | 1459 | | } |
| | | 1460 | | |
| | | 1461 | | ~Http3ReadStream() |
| | 0 | 1462 | | { |
| | 0 | 1463 | | Dispose(false); |
| | 0 | 1464 | | } |
| | | 1465 | | |
| | | 1466 | | protected override void Dispose(bool disposing) |
| | 0 | 1467 | | { |
| | 0 | 1468 | | Http3RequestStream? stream = Interlocked.Exchange(ref _stream, null); |
| | 0 | 1469 | | if (stream is null) |
| | 0 | 1470 | | { |
| | 0 | 1471 | | return; |
| | | 1472 | | } |
| | | 1473 | | |
| | 0 | 1474 | | if (disposing) |
| | 0 | 1475 | | { |
| | | 1476 | | // This will remove the stream from the connection properly. |
| | 0 | 1477 | | stream.Dispose(); |
| | 0 | 1478 | | } |
| | | 1479 | | else |
| | 0 | 1480 | | { |
| | | 1481 | | // We shouldn't be using a managed instance here, but don't have much choice -- we |
| | | 1482 | | // need to remove the stream from the connection's GOAWAY collection and properly abort. |
| | 0 | 1483 | | stream.AbortStream(); |
| | 0 | 1484 | | stream._connection.RemoveStream(stream._stream); |
| | 0 | 1485 | | stream._connection = null!; |
| | 0 | 1486 | | } |
| | | 1487 | | |
| | 0 | 1488 | | _response = null; |
| | | 1489 | | |
| | 0 | 1490 | | base.Dispose(disposing); |
| | 0 | 1491 | | } |
| | | 1492 | | |
| | | 1493 | | public override async ValueTask DisposeAsync() |
| | 0 | 1494 | | { |
| | 0 | 1495 | | Http3RequestStream? stream = Interlocked.Exchange(ref _stream, null); |
| | 0 | 1496 | | if (stream is null) |
| | 0 | 1497 | | { |
| | 0 | 1498 | | return; |
| | | 1499 | | } |
| | | 1500 | | |
| | 0 | 1501 | | await stream.DisposeAsync().ConfigureAwait(false); |
| | | 1502 | | |
| | 0 | 1503 | | _response = null; |
| | | 1504 | | |
| | 0 | 1505 | | await base.DisposeAsync().ConfigureAwait(false); |
| | 0 | 1506 | | } |
| | | 1507 | | |
| | | 1508 | | public override int Read(Span<byte> buffer) |
| | 0 | 1509 | | { |
| | 0 | 1510 | | Http3RequestStream? stream = _stream; |
| | 0 | 1511 | | ObjectDisposedException.ThrowIf(stream is null, this); |
| | | 1512 | | |
| | 0 | 1513 | | Debug.Assert(_response != null); |
| | 0 | 1514 | | return stream.ReadResponseContent(_response, buffer); |
| | 0 | 1515 | | } |
| | | 1516 | | |
| | | 1517 | | public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken) |
| | 0 | 1518 | | { |
| | 0 | 1519 | | Http3RequestStream? stream = _stream; |
| | | 1520 | | |
| | 0 | 1521 | | if (stream is null) |
| | 0 | 1522 | | { |
| | 0 | 1523 | | return ValueTask.FromException<int>(ExceptionDispatchInfo.SetCurrentStackTrace(new ObjectDisposedExc |
| | | 1524 | | } |
| | | 1525 | | |
| | 0 | 1526 | | Debug.Assert(_response != null); |
| | 0 | 1527 | | return stream.ReadResponseContentAsync(_response, buffer, cancellationToken); |
| | 0 | 1528 | | } |
| | | 1529 | | |
| | | 1530 | | public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken) |
| | 0 | 1531 | | { |
| | 0 | 1532 | | throw new NotSupportedException(); |
| | | 1533 | | } |
| | | 1534 | | } |
| | | 1535 | | |
| | | 1536 | | // TODO: it may be possible for Http3RequestStream to implement Stream directly and avoid this allocation. |
| | | 1537 | | private sealed class Http3WriteStream : HttpBaseStream |
| | | 1538 | | { |
| | | 1539 | | private Http3RequestStream? _stream; |
| | | 1540 | | |
| | 0 | 1541 | | public long BytesWritten { get; private set; } |
| | | 1542 | | |
| | 0 | 1543 | | public override bool CanRead => false; |
| | | 1544 | | |
| | 0 | 1545 | | public override bool CanWrite => _stream != null; |
| | | 1546 | | |
| | 0 | 1547 | | public Http3WriteStream(Http3RequestStream stream) |
| | 0 | 1548 | | { |
| | 0 | 1549 | | _stream = stream; |
| | 0 | 1550 | | } |
| | | 1551 | | |
| | | 1552 | | protected override void Dispose(bool disposing) |
| | 0 | 1553 | | { |
| | 0 | 1554 | | _stream = null; |
| | 0 | 1555 | | base.Dispose(disposing); |
| | 0 | 1556 | | } |
| | | 1557 | | |
| | | 1558 | | public override int Read(Span<byte> buffer) |
| | 0 | 1559 | | { |
| | 0 | 1560 | | throw new NotSupportedException(); |
| | | 1561 | | } |
| | | 1562 | | |
| | | 1563 | | public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken) |
| | 0 | 1564 | | { |
| | 0 | 1565 | | throw new NotSupportedException(); |
| | | 1566 | | } |
| | | 1567 | | |
| | | 1568 | | public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken) |
| | 0 | 1569 | | { |
| | 0 | 1570 | | BytesWritten += buffer.Length; |
| | | 1571 | | |
| | 0 | 1572 | | Http3RequestStream? stream = _stream; |
| | | 1573 | | |
| | 0 | 1574 | | if (stream is null) |
| | 0 | 1575 | | { |
| | 0 | 1576 | | return ValueTask.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new ObjectDisposedExceptio |
| | | 1577 | | } |
| | | 1578 | | |
| | 0 | 1579 | | return stream.WriteRequestContentAsync(buffer, cancellationToken); |
| | 0 | 1580 | | } |
| | | 1581 | | |
| | | 1582 | | public override Task FlushAsync(CancellationToken cancellationToken) |
| | 0 | 1583 | | { |
| | 0 | 1584 | | Http3RequestStream? stream = _stream; |
| | | 1585 | | |
| | 0 | 1586 | | if (stream is null) |
| | 0 | 1587 | | { |
| | 0 | 1588 | | return Task.FromException(ExceptionDispatchInfo.SetCurrentStackTrace(new ObjectDisposedException(nam |
| | | 1589 | | } |
| | | 1590 | | |
| | 0 | 1591 | | return stream.FlushSendBufferAsync(endStream: false, cancellationToken).AsTask(); |
| | 0 | 1592 | | } |
| | | 1593 | | } |
| | | 1594 | | |
| | | 1595 | | private enum HeaderState |
| | | 1596 | | { |
| | | 1597 | | StatusHeader, |
| | | 1598 | | SkipExpect100Headers, |
| | | 1599 | | ResponseHeaders, |
| | | 1600 | | TrailingHeaders |
| | | 1601 | | } |
| | | 1602 | | } |
| | | 1603 | | } |