@@ -54,6 +54,9 @@ var bytePool1k = teautils.NewBytePool(20480, 1024)
5454var bytePool32k = teautils .NewBytePool (20480 , 32 * 1024 )
5555var bytePool128k = teautils .NewBytePool (20480 , 128 * 1024 )
5656
57+ // 环境变量
58+ var HOSTNAME , _ = os .Hostname ()
59+
5760// 请求定义
5861// HTTP HEADER RFC: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
5962type Request struct {
@@ -1270,6 +1273,8 @@ func (this *Request) Format(source string) string {
12701273 return this .serverName
12711274 case "serverPort" :
12721275 return strconv .Itoa (this .requestServerPort ())
1276+ case "hostname" :
1277+ return HOSTNAME
12731278 case "documentRoot" :
12741279 if this .locationContext != nil && len (this .locationContext .Root ) > 0 {
12751280 return this .locationContext .Root
@@ -1305,6 +1310,13 @@ func (this *Request) Format(source string) string {
13051310 switch suffix {
13061311 case "address" :
13071312 return this .backend .Address
1313+ case "host" :
1314+ index := strings .Index (this .backend .Address , ":" )
1315+ if index > - 1 {
1316+ return this .backend .Address [:index ]
1317+ } else {
1318+ return ""
1319+ }
13081320 case "id" :
13091321 return this .backend .Id
13101322 case "scheme" :
@@ -1432,9 +1444,16 @@ func (this *Request) log() {
14321444 cookies [cookie .Name ] = cookie .Value
14331445 }
14341446
1447+ addr := this .raw .RemoteAddr
1448+ host , _ , err := net .SplitHostPort (addr )
1449+ if err == nil {
1450+ addr = host
1451+ }
1452+
14351453 accessLog := & accesslogs.AccessLog {
14361454 TeaVersion : teaconst .TeaVersion ,
14371455 RemoteAddr : this .requestRemoteAddr (),
1456+ RawRemoteAddr : addr ,
14381457 RemotePort : this .requestRemotePort (),
14391458 RemoteUser : this .requestRemoteUser (),
14401459 RequestURI : this .requestURI (),
@@ -1469,6 +1488,7 @@ func (this *Request) log() {
14691488 HasErrors : len (this .errors ) > 0 ,
14701489 Extend : & accesslogs.AccessLogExtend {},
14711490 Attrs : this .attrs ,
1491+ Hostname : HOSTNAME ,
14721492 }
14731493
14741494 // 日志和统计
@@ -1501,6 +1521,8 @@ func (this *Request) log() {
15011521 if this .backend != nil {
15021522 accessLog .BackendAddress = this .backend .Address
15031523 accessLog .BackendId = this .backend .Id
1524+ accessLog .BackendScheme = this .backend .Scheme
1525+ accessLog .BackendCode = this .backend .Code
15041526 }
15051527
15061528 if this .fastcgi != nil {
0 commit comments