Exemplo n.º 1
0
        internal static async Task SetStatusLineAsync(this HttpResponseMessage response, IAsyncEnumerator <byte> enumerator,
                                                      CancellationToken cancellationToken)
        {
            // Validate parameters.
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }
            if (enumerator == null)
            {
                throw new ArgumentNullException(nameof(enumerator));
            }

            // Match the line.
            Match match = await enumerator.MatchLineAsync(StatusLineRegex, cancellationToken).ConfigureAwait(false);

            // Get the groups and set.
            response.Version      = new Version(match.GetGroupValue("version"));
            response.StatusCode   = (HttpStatusCode)Int32.Parse(match.GetGroupValue("statusCode"));
            response.ReasonPhrase = match.GetGroupValue("reasonPhrase");
        }