Skip to content

Commit 2b7f0d2

Browse files
committed
✨ feat(models): 增加流量模型的請求標頭屬性
在流量中介層和流量模型中新增了多個請求標頭屬性, 包括 Referer、Cf-Connecting-Ip、X-Client-Ip、X-Origin-Forwarded-For、 X-Forwarded-For 和 X-Real-Ip,以便更好地追蹤和記錄請求來源。
1 parent 845acc0 commit 2b7f0d2

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/Netcorext.Auth.Authentication/Middlewares/TrafficMiddleware.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ public async Task InvokeAsync(HttpContext context)
3737
Host = context.Request.Host.Value,
3838
Path = context.Request.Path,
3939
QueryString = context.Request.QueryString.Value,
40+
Referer = context.Request.Headers.Referer,
4041
Headers = context.Request.Headers.GetHeadersString(),
4142
ResponseHeaders = context.Response.Headers.GetHeadersString(),
4243
Ip = context.GetIp(),
44+
CfConnectingIp = context.Request.Headers["Cf-Connecting-Ip"],
45+
XClientIp = context.Request.Headers["X-Client-Ip"],
46+
XOriginForwardedFor = context.Request.Headers["X-Origin-Forwarded-For"],
47+
XForwardedFor = context.Request.Headers["X-Forwarded-For"],
48+
XRealIp = context.Request.Headers["X-Real-Ip"],
4349
TraceIdentifier = context.TraceIdentifier,
4450
StatusCode = context.Response.StatusCode.ToString(),
4551
Elapsed = watcher.Elapsed,

src/Netcorext.Auth.Core/Models/Traffic.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ public class Traffic
1010
public string Host { get; set; } = null!;
1111
public string Path { get; set; } = null!;
1212
public string? QueryString { get; set; }
13+
public string? Referer { get; set; }
1314
public string? Headers { get; set; }
1415
public string? ResponseHeaders { get; set; }
1516
public string StatusCode { get; set; } = null!;
1617
public TimeSpan Elapsed { get; set; }
1718
public string? DeviceId { get; set; }
1819
public string? Ip { get; set; }
20+
public string? CfConnectingIp { get; set; }
21+
public string? XClientIp { get; set; }
22+
public string? XOriginForwardedFor { get; set; }
23+
public string? XForwardedFor { get; set; }
24+
public string? XRealIp { get; set; }
1925
public string? TraceIdentifier { get; set; }
2026
public string? XRequestId { get; set; }
2127
public UserAgent? UserAgent { get; set; }

0 commit comments

Comments
 (0)