internal static void AddXForwardedHeaders( this WebSocketClientOptions options, IPAddress @for, HostString host, string proto, PathString pathBase) { if (@for != null) { var forString = @for.AddressFamily == AddressFamily.InterNetworkV6 ? $"\"[{@for}]\"" : @for.ToString(); options.SetRequestHeader(XForwardedFor, forString); } if (host.HasValue) { options.SetRequestHeader(XForwardedHost, host.Value); } if (!string.IsNullOrWhiteSpace(proto)) { options.SetRequestHeader(XForwardedProto, proto); } if (!string.IsNullOrWhiteSpace(pathBase)) { options.SetRequestHeader(XForwardedPathBase, pathBase); } }
/// <summary> /// Adds X-Forwarded-* headers to the upstream websocket request /// with an additional PathBase parameter. /// </summary> public static void AddXForwardedHeaders(this WebSocketClientOptions options) { var protocol = options.HttpContext.Request.Scheme; var @for = options.HttpContext.Connection.RemoteIpAddress; var host = options.HttpContext.Request.Headers[HeaderNames.Host]; var hostString = HostString.FromUriComponent(host); var pathBase = options.HttpContext.Request.PathBase.Value; options.AddXForwardedHeaders(@for, hostString, protocol, pathBase); }