| | | 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.Diagnostics.CodeAnalysis; |
| | | 5 | | using System.Diagnostics.Tracing; |
| | | 6 | | |
| | | 7 | | namespace System.Net.Http |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Represents the context passed to the ConnectCallback for a SocketsHttpHandler instance. |
| | | 11 | | /// </summary> |
| | | 12 | | public sealed class SocketsHttpConnectionContext |
| | | 13 | | { |
| | | 14 | | private readonly DnsEndPoint _dnsEndPoint; |
| | | 15 | | private readonly HttpRequestMessage _initialRequestMessage; |
| | | 16 | | private readonly long _connectionId; |
| | | 17 | | |
| | 0 | 18 | | internal SocketsHttpConnectionContext(DnsEndPoint dnsEndPoint, HttpRequestMessage initialRequestMessage, long co |
| | 0 | 19 | | { |
| | 0 | 20 | | _dnsEndPoint = dnsEndPoint; |
| | 0 | 21 | | _initialRequestMessage = initialRequestMessage; |
| | 0 | 22 | | _connectionId = connectionId; |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// The DnsEndPoint to be used by the ConnectCallback to establish the connection. |
| | | 27 | | /// </summary> |
| | 0 | 28 | | public DnsEndPoint DnsEndPoint => _dnsEndPoint; |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// The initial HttpRequestMessage that is causing the connection to be created. |
| | | 32 | | /// </summary> |
| | 0 | 33 | | public HttpRequestMessage InitialRequestMessage => _initialRequestMessage; |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// The identifier that will be assigned to the connection being established. This matches the connection id |
| | | 37 | | /// reported through <see cref="EventSource"/> telemetry, the |
| | | 38 | | /// <see cref="SocketsHttpConnectionEvictionContext.ConnectionId"/> passed to |
| | | 39 | | /// <see cref="SocketsHttpHandler.ShouldEvictConnection"/>, and the |
| | | 40 | | /// <see cref="HttpRequestMessage.ConnectionId"/> stamped on requests sent over the connection. It can be used |
| | | 41 | | /// to associate caller state (for example, the resolved address used) with the connection and to correlate it |
| | | 42 | | /// with the requests it serves, so that state can be recovered later (for example when deciding on eviction). |
| | | 43 | | /// </summary> |
| | | 44 | | /// <remarks> |
| | | 45 | | /// When establishing the transport for an HTTP CONNECT proxy tunnel, this id identifies that transport |
| | | 46 | | /// connection to the proxy; the tunneled connection layered over it serves the requests and carries a distinct |
| | | 47 | | /// id, which is the one reported to <see cref="SocketsHttpHandler.ShouldEvictConnection"/> and stamped on those |
| | | 48 | | /// requests. A <see cref="SocketsHttpHandler.PlaintextStreamFilter"/> runs on each hop and surfaces both: this |
| | | 49 | | /// (transport) id on the CONNECT hop and the tunneled connection's id on the subsequent hop. |
| | | 50 | | /// </remarks> |
| | | 51 | | [Experimental(Experimentals.SocketsHttpHandlerExperimentalDiagId, UrlFormat = Experimentals.SharedUrlFormat)] |
| | 0 | 52 | | public long ConnectionId => _connectionId; |
| | | 53 | | } |
| | | 54 | | } |
| | | 55 | | |