Repository: dotnet/aspnetcore
File: src/Servers/HttpSys/test/FunctionalTests/RequestTests.cs (C#)

Code before:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Text;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.HttpSys.Internal;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Server.HttpSys;

public class RequestTests : LoggedTest
{
    [ConditionalFact]
    public async Task Request_SimpleGet_ExpectedFieldsSet()
    {
        string root;
        using (Utilities.CreateHttpServerReturnRoot("/basepath", out root, async httpContext =>
        {
            var requestInfo = httpContext.Features.Get<IHttpRequestFeature>();

            // Request Keys
            Assert.Equal("GET", requestInfo.Method);
            Assert.Equal(Stream.Null, requestInfo.Body);
            Assert.NotNull(requestInfo.Headers);
            Assert.Equal("http", requestInfo.Scheme);
            Assert.Equal("/basepath", requestInfo.PathBase);
            Assert.Equal("/SomePath", requestInfo.Path);
            Assert.Equal("?SomeQuery", requestInfo.QueryString);
            Assert.Equal("/basepath/SomePath?SomeQuery", requestInfo.RawTarget);
            Assert.Equal("HTTP/1.1", requestInfo.Protocol);

            Assert.False(httpContext.Request.CanHaveBody());
            var connectionInfo = httpContext.Features.Get<IHttpConnectionFeature>();
            Assert.Equal("::1", connectionInfo.RemoteIpAddress.ToString());
            Assert.NotEqual(0, connectionInfo.RemotePort);
            Assert.Equal("::1", connectionInfo.LocalIpAddress.ToString());
            Assert.NotEqual(0, connectionInfo.LocalPort);
            Assert.NotNull(connectionInfo.ConnectionId);

            // Trace identifier
            var requestIdentifierFeature = httpContext.Features.Get<IHttpRequestIdentifierFeature>();
            Assert.NotNull(requestIdentifierFeature);

Review comment (suggestion):
```suggestion
        using (Utilities.CreateHttpServerReturnRoot("/basepath", out root, httpContext =>
```

Code after:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Text;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.HttpSys.Internal;
using Microsoft.AspNetCore.InternalTesting;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Server.HttpSys;

public class RequestTests : LoggedTest
{
    [ConditionalFact]
    public async Task Request_SimpleGet_ExpectedFieldsSet()
    {
        string root;
        using (Utilities.CreateHttpServerReturnRoot("/basepath", out root, httpContext =>
        {
            var requestInfo = httpContext.Features.Get<IHttpRequestFeature>();

            // Request Keys
            Assert.Equal("GET", requestInfo.Method);
            Assert.Equal(Stream.Null, requestInfo.Body);
            Assert.NotNull(requestInfo.Headers);
            Assert.Equal("http", requestInfo.Scheme);
            Assert.Equal("/basepath", requestInfo.PathBase);
            Assert.Equal("/SomePath", requestInfo.Path);
            Assert.Equal("?SomeQuery", requestInfo.QueryString);
            Assert.Equal("/basepath/SomePath?SomeQuery", requestInfo.RawTarget);
            Assert.Equal("HTTP/1.1", requestInfo.Protocol);

            Assert.False(httpContext.Request.CanHaveBody());
            var connectionInfo = httpContext.Features.Get<IHttpConnectionFeature>();
            Assert.Equal("::1", connectionInfo.RemoteIpAddress.ToString());
            Assert.NotEqual(0, connectionInfo.RemotePort);
            Assert.Equal("::1", connectionInfo.LocalIpAddress.ToString());
            Assert.NotEqual(0, connectionInfo.LocalPort);
            Assert.NotNull(connectionInfo.ConnectionId);

            // Trace identifier
            var requestIdentifierFeature = httpContext.Features.Get<IHttpRequestIdentifierFeature>();
            Assert.NotNull(requestIdentifierFeature);