Przeglądaj źródła

another nginx x-forwarded-for try

Tobias von Dewitz 6 lat temu
rodzic
commit
efcba1d358
1 zmienionych plików z 7 dodań i 9 usunięć
  1. 7 9
      main.go

+ 7 - 9
main.go

@@ -265,6 +265,9 @@ func nginxLogCapture(logfile, format string) {
 	reqRegexp := regexp.MustCompile(`^([A-Z]+)\s+(.+?)\s+(HTTP/\d+\.\d+)$`)
 
 	for line := range t.Lines {
+		var remote string
+		var err error
+
 		l := line.Text
 
 		logEntry, err := p.ParseString(l)
@@ -277,20 +280,15 @@ func nginxLogCapture(logfile, format string) {
 			pretty.Println(logEntry)
 		}
 
-		remote, err := logEntry.Field("remote_addr")
+		remote, err = logEntry.Field("remote_addr")
 		if err != nil {
 			log.Println(err)
 			continue
 		}
 
-		if config.UseXForwardedAsSource {
-			xff, err := logEntry.Field("http_x_forwarded_for")
-			if err != nil && xff != "" {
-				ips := strings.Split(xff, ",")
-				if len(ips) > 0 {
-					remote = strings.TrimSpace(ips[0])
-				}
-			}
+		xff, err := logEntry.Field("http_x_forwarded_for")
+		if err != nil && xff != "" {
+			remote = xff
 		}
 
 		if remote == "" {